我正在使用描述为的 wsdl:
<wsdl:binding name="PassengerConformance_v1Binding"
type="tns:PassengerConformanceAuthenticationPortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="identify">
</wsdl:operation>
</wsdl:binding>
但是生成的请求是 UTF16,服务器希望是 utf-8 这就是我的代码的样子
var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport)
{
Security = new BasicHttpSecurity
{
Mode = BasicHttpSecurityMode.Transport,
Transport = new HttpTransportSecurity
{
ClientCredentialType = HttpClientCredentialType.Digest
}
}
};
var address = new EndpointAddress(dcsServiceConfiguration.Url);
var channel = new ChannelFactory<T>(binding, address);
channel.Credentials.HttpDigest.ClientCredential =
new NetworkCredential(username, Password);
var buildDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filePath = buildDir + @"\ClientCert.pfx";
channel.Credentials.ClientCertificate.Certificate =
new X509Certificate2(filePath, "password", X509KeyStorageFlags.MachineKeySet);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
return channel;
我知道 BasicHttpBinding 默认 textEncoding 值是 utf-8,但是当我检查消息检查器时,它仍然是 utf-16。
我注意到当我在 .net 7.2 框架控制台应用程序中复制此代码时,没有 xml 标记。这仍然对我有用请帮助。