繁体   English   中英

SOAP HTTPS服务在C#中使用

[英]SOAP HTTPS Services consume in c#

我正在尝试使用HTTPS SOAP服务,该服务具有对其进行授权的凭据并得到以下错误:

mscorlib.dll中发生了类型为'System.ServiceModel.ProtocolException'的未处理异常

附加信息:内容类型为text / html; 响应消息的charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8)。 如果使用自定义编码器,请确保正确实施IsContentTypeSupported方法。 响应的前1024个字节为:'

绑定如下。 我有什么想念的吗?

<endpoint address="https://...."
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IInboundService1"
          contract="RQSInboundExternal.IInboundService" name="BasicHttpBinding_IInboundServiceQSPort">

<basicHttpBinding>              
            <binding name="BasicHttpBinding_IInboundService1" >                  
              <security mode="Transport" >
               <transport clientCredentialType="Basic"/>                   
              </security>
            </binding>
        </basicHttpBinding>

在此处设置用户名和密码。 这也需要发送。 如果我们仅发送标题,则它不起作用。

client.ClientCredentials.UserName.UserName = "";
client.ClientCredentials.UserName.Password = "";

var httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(client.ClientCredentials.UserName.UserName + ":" + client.ClientCredentials.UserName.Password));
            client.Open();
            var context = new OperationContext(client.InnerChannel);
            using (new OperationContextScope(context))
            {
                context.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;

                client.SampleMethodCall();
            }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM