SOAP ヘッダーを必要とする ASMX Web サービスと、サービス参照 (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: サーバーは要求を処理できませんでした。---> コンピュータ名を取得できませんでした。 サーバー スタック トレース: System.ServiceModel.Channels.ServiceChannel.HandleReply (ProxyOperationRuntime 操作、ProxyRpc & rpc) で System.ServiceModel.Channels.ServiceChannel.Call (文字列アクション、ブール値一方向、ProxyOperationRuntime 操作、オブジェクト [] イン、オブジェクト [] アウト、TimeSpan タイムアウト) で System.ServiceModel.Channels.ServiceChannel.Call (文字列アクション、ブール値一方向、ProxyOperationRuntime 操作、オブジェクト [] イン、オブジェクト [] アウト) で System.ServiceModel.Channels.ServiceChannelProxy.InvokeService (IMethodCallMessage methodCall、ProxyOperationRuntime 操作) で System.ServiceModel.Channels.ServiceChannelProxy.Invoke (IMessage メッセージ) で
まだ WCF を使用しているクライアント側でこれを修正するにはどうすればよいですか? サーバー コードを変更できず、クライアントで WCF を使用する必要があります。Web 参照を追加できません。