1

Web サービス参照をプログラムで定義できる C# で Web サービスにアクセスする標準的な方法を知りたいと思いました。

次のシナリオがあります。

  1. 複数の Web サービスをプログラムでセットアップできます。したがって、Visual Studio が提供する「Web サービス参照の追加」を使用できません (または、間違っている場合は正しいと思います)。
  2. 追加された Web サービスは同じ構造/アクション/操作/要求/応答を持ちますが、異なるデータを供給する異なるドメインに属している可能性があります。

例:

  webservice 01 :  http://abc.example.com/getData
  webservice 02 :  http://xyz.example.net/getData
  1. あるサービスから生成されたプロキシを使用して別のサービスに使用することはできますか? それとも生の XML 応答を処理する必要がありますか?

編集01:Webサービスにアクセスする次のスニペットを一般化して、すべてのWebサービスに使用できるかどうか知りたい

        var binding = new BasicHttpBinding();
        var address = new EndpointAddress("http://www.abc.com/service.asmx");
        var factory = new ChannelFactory<IGeneralProxy>(binding, address);

        var obj = factory.CreateChannel();
        var responseString = obj.GetData("UserName", "Password");
        Assert.IsNotNull(responseString);

IGeneralProxyクライアントのインターフェースはどこですか

上記の点で不明な点があれば教えてください。

4

3 に答える 3

1

Yes, you can use the same generated proxy for both services as long as the service is the same. I do it all the time.

Here is a snipit of my code. I use WSE 3.0 as the project that I am working on is .net 2.0.

ServiceWse serivce = new ServiceWse();
CookieContainer cookieContainer = new CookieContainer();
serivce.Timeout = 1000 * 60 * CommonFunctions.GetConfigValue<int>(Consts.Common.WebServiceTimeout, 20);
serivce.Url = CommonFunctions.GetConfigValue(Consts.Urls.MyServiceSecuredURL, string.Empty);
serivce.CookieContainer = cookieContainer;
if (CommonFunctions.GetConfigValue(Consts.Security.UseSecuredServices, false))
    CommonFunctions.SetWSSecurity(_service.RequestSoapContext);
于 2012-06-05T15:21:39.127 に答える
0

同様の質問に対するこの以前の回答を確認してください。

プログラムでクライアントを WCF サービスに接続する方法は?

これは、Web サービスごとに行うことができます。

于 2012-06-05T15:17:51.353 に答える
0

私たちは似たようなことをします。Web サービス参照は、サービスの Dev バージョンに対して作成されます。また、サービスをインスタンス化するときに使用する各 Web サービス URI の web.config にも設定があります。そうすれば、本番環境にデプロイするときに、プロジェクトを再構築するのではなく、web.config の URI を変更するだけで済みます。

var myService= new myService(){Uri = [service uri from web.config]};
于 2012-06-05T15:18:01.773 に答える