1

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 参照を追加できません。

4

2 に答える 2

1

先ほど回答した別の質問 (SOAP ヘッダーの読み取りについて) に基づいて、このアプローチは、WCF クライアントから ASMX サービスを呼び出すときに SOAP ヘッダーを含めるという要件に対して機能するはずです。

Service1SoapClient client = new Service1SoapClient(binding, address);

using(OperationContextScope scope = new OperationContextScope(client.InnerChannel))
{
    // set the message in header
    MessageHeader header = MessageHeader.CreateHeader("MyHeader", "urn:Sample-NS", "Some Value");
    OperationContext.Current.OutgoingMessageHeaders.Add(header); 

    string expected = client.MyMethod(new MyCustomSoapHeader(){SomeProperty = true});
}

これが機能することを願っています-現在、これをテストするためのインフラストラクチャが手元にありません...

于 2010-10-01T21:05:02.877 に答える
0

この時点での問題はSOAPヘッダーにまったく関連していないようです...「コンピューター名を取得できませんでした」というエラーは別の場所から発生しています。

クライアントでサービスURLとして何を指定していますか?サービスはクライアントと同じマシンで実行されていますか、それとも別のマシンで実行されていますか?サービスは他の非WCFクライアントと連携していますか?

于 2010-09-30T23:05:41.083 に答える