简体   繁体   English

SOAP HTTPS服务在C#中使用

[英]SOAP HTTPS Services consume in c#

I am trying to consume HTTPS SOAP Service which has credentials to authorise it and get the below error: 我正在尝试使用HTTPS SOAP服务,该服务具有对其进行授权的凭据并得到以下错误:

An unhandled exception of type 'System.ServiceModel.ProtocolException' occurred in mscorlib.dll mscorlib.dll中发生了类型为'System.ServiceModel.ProtocolException'的未处理异常

Additional information: The content type text/html; 附加信息:内容类型为text / html; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). 响应消息的charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8)。 If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. 如果使用自定义编码器,请确保正确实施IsContentTypeSupported方法。 The first 1024 bytes of the response were: ' 响应的前1024个字节为:'

Bindings are below. 绑定如下。 Am I missing anything? 我有什么想念的吗?

<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>

set username and password here. 在此处设置用户名和密码。 This is also required to be sent. 这也需要发送。 If we only send in the header it is not working. 如果我们仅发送标题,则它不起作用。

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