Ehsan Sajjad
Ehsan Sajjad

Reputation: 62498

Call Soap Service From a Windows Service

I am consuming a Soap service http://example.com/soap/webservice.php in my desktop application . i created a separate class library Included the service and used this class library to consume it in my main application which i working fine.

Here is the code i am using:

MyService.PushServerWSPortTypeClient obj = new MyService.PushServerWSPortTypeClient();

string result = obj.auth(apiId, UserName, Password);

This is working perfect.

But when i use this service in my windows service i am getting the exception:

There was no endpoint listening at http://exmaple.com/soap/webservice.php that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

I know what this exception means that it is unable to find endpoint of it in my service, but in my class library endpoints are mentioned in it's app.config and i also added these endpoints in my windows service app.config as well.

Here is the code from app.config:

<system.serviceModel>
      <bindings>
          <basicHttpBinding>
              <binding name="PushServerWSBinding" />
          </basicHttpBinding>
      </bindings>
      <client>
          <endpoint address="http://example.com/soap/webservice.php"
              binding="basicHttpBinding" bindingConfiguration="PushServerWSBinding"
              contract="MyService.PushServerWSPortType" name="PushServerWSPort" />
      </client>
  </system.serviceModel>

Inner Exception Message :

The remote name could not be resolved: 'api.example.com'

Stack Trace :

at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()

Upvotes: 0

Views: 2366

Answers (2)

Ehsan Sajjad
Ehsan Sajjad

Reputation: 62498

After digging one complete day,Today we contacted our Networks Department for this weird issue and we came to know that When we use Desktop Application to call any SOAP or WCF Service the request goes through Proxy Server, but in the case of Windows Service the request goes through System Gateway/Firewall and on Firewall port 80 was blocked, due to which the request was unable to call server.

When we opened the port 80 for the service specific url it started wroking normally.

Upvotes: 0

SanyTiger
SanyTiger

Reputation: 666

It is possible that your browser uses some proxy where your code does not (or use different one).

If it is the case make sure to set WebClient.Proxy property to match one in the browser, making use of the WebProxy class using

WebClient webClient = new WebClient()) 
{ 
  webClient.Proxy = new WebProxy("myproxy.com"); 
  result= webClient.DownloadString(someURL);
}

If not sure, try out his DNS-Testing link. It is unlikely, but possible if browser uses different DNS than your code.

Upvotes: 1

Related Questions