У меня есть веб-сервис ASMX, для которого требуется заголовок soap и клиентское приложение, использующее этот сервис через ссылку на сервис (WCF).
Сервер:
[WebService(Namespace = "http://myserviceurl.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service1 : System.Web.Services.WebService
{
public MyCustomSoapHeader MyHeader;
[WebMethod]
[SoapHeader("MyHeader", Direction = SoapHeaderDirection.In)]
public string MyMethod()
{
if(MyHeader.SomeProperty == false)
{
return "error";
}
return "success";
}
public class MyCustomSoapHeader: SoapHeader
{
public bool SomeProperty { get; set; }
}
}
Клиент:
public class MyClient
{
var address = new EndpointAddress(_myServerUrl)
var binding = new BasicHttpBinding();
binding.Name = "SoapBinding";
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.ReceiveTimeout = TimeSpan.FromSeconds(_timeout);
Service1SoapClient client = new Service1SoapClient(binding, address);
string expected = client.MyMethod(new MyCustomSoapHeader(){SomeProperty = true});
}
Трассировка стека:
System.ServiceModel.FaultException: Server was unable to process request. ---> Computer name could not be obtained.
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Как я могу исправить это на стороне клиента, все еще используя WCF? Я не могу изменить код сервера и мне нужно использовать WCF на клиенте, я не могу добавить веб-ссылку.