سؤال

I need to use a web service that has the following requirements:

  • https/ssl
  • MTOM
  • user/password needs to be specified in the SOAP header
  • 1 (possibly large) binary file as payload

I do not control this web service and need to consume it. Since I am new to WCF, I need help with some basic stuff. My questions are:

  1. When I add a service reference in VS2010 I get a basichttpbinding in the config. I think I must use wshttpbinding, am I right? Where/how do I change/configure it? Directly in the config?
  2. How do configure my client to specify the user/password in the soap header?
  3. How do I "attach" a binary file?

Thanks

هل كانت مفيدة؟

المحلول

If you add service reference and you don't get any error, warning or any commented section in configuration file you already have what you need. Just use the code you get. The reference will create client proxy for you and this will have methods needed to pass binary data to the server. Proxy also allows setting client credentials:

var proxy = new ServiceContractNameClient();
proxy.ClientCredentials.UserName.Name = "userName";
proxy.ClientCredentials.UserName.Password = "pwd";
var result = proxy.SendSomeVeryLargeData(new SomeDataContract() { Data = yourData });

BasicHttpBinding supports both credentials in SOAP header and MTOM encoding.

نصائح أخرى

Usually when you consuming web service, you don't need to change binding.

You may need to specify Client credentials.

   Service1Client service = new Service1Client();
   service.ClientCredentials.UserName.UserName = "user";
   service.ClientCredentials.UserName.Password = "pass";

See this article.

I found a good article on how to configure MTOM client with WCF. This is a very basic tutorial. I hope it helps.

http://mstecharchitect.blogspot.com/2009/01/wcf-with-mtom-message-encoding.html

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top