SOAP HTTPS服务在c#中消耗

时间:2018-05-15 16:40:15

标签: c# soap basichttpbinding

我正在尝试使用HTTPS SOAP Service,它具有授权它的凭据并获得以下错误:

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>

1 个答案:

答案 0 :(得分:0)

在此处设置用户名和密码。这也需要发送。如果我们只发送标题,它就无法正常工作。

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();
            }