我有一个ASMX Web服务,它需要一个SOAP头和一个客户端应用程序通过服务引用(WCF)使用此服务。WCF客户端使用带SOAP头的ASMX Web服务
服务器:
[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,我无法添加Web引用。
客户端的URL是“http://MyServer/Services/Service1.asmx”。为了开发,客户端与服务在同一台机器上运行。但是,在生产中它不会。我有一种感觉,我的直觉是这是一个环境问题,而不是WCF问题,但如果我们可以在同一个盒子上运行服务和客户端用于开发/测试目的,那将是非常好的。该服务对非WCF客户端工作正常。 – Adam 2010-10-01 13:21:42
因为两者都在同一台计算机上,所以如果您使用localhost而不是MyServer指定URL,它是否工作?听起来像一个DNS问题可能会阻碍。 – tomasr 2010-10-01 14:50:10
刚刚尝试将端点切换到本地主机。同样的例外。 – Adam 2010-10-01 16:16:36