0

I have a normal 3rd party SOAP service with WSDL and stuff. The problem is - it only accepts GET requests. How can I access it in c#?

When I add that service to VS via Add Service Reference and try to use it as usual:

var service = new BaseSvcClient(
                 new BasicHttpContextBinding(), 
                 new EndpointAddress("http://some.internal.ip/WebServices/Base.svc"));
var ver = service.Version();

I see (via fiddler) that it actually sends POST requests and web-service responds with Endpoint not found error message. If I simply hit http://some.internal.ip/WebServices/Base.svc/Version in a browser the proper xml is returned.

I can use WebClient, but then I have to construct all the GET requests manually, which doesn't look good. Are there other solutions?

horgh
  • 17,918
  • 22
  • 68
  • 123
Shaddix
  • 5,901
  • 8
  • 45
  • 86
  • After you add it as usual, take a good look at the generated config. Your config-by-code relies on all defaults. I think you're missing a behavior or two. – H H Oct 03 '12 at 08:50
  • weid to me, service public as SOAP, how can you access by REST? – cuongle Oct 03 '12 at 09:09
  • unfortunately after adding a service (References->right click->Add service reference) I have nothing added to my app.config (it's just , so don't know where to take missing behaviors from – Shaddix Oct 03 '12 at 09:13
  • @Cuong probably it's something like wcf service with `WebInvoke` attributes and `UriTemplate`s but don't know exactly – Shaddix Oct 03 '12 at 09:21
  • Yes, there's a WSDL available at `/Base.svc?wsdl` and even a help page at `Base.svc/help` which lists the actions with their urls and methods like: `Version GET Base.svc/Version; Echo GET Base.svc/Echo?value={VALUE}` etc – Shaddix Oct 03 '12 at 09:32

2 Answers2

1

I have found an answer that helped me a lot. Basically if I take an autogenerated interface for the client, decorate methods with [WebGet] and use

var cf = new WebChannelFactory<IBaseSvc2>(new Uri("..."));
var service = cf.CreateChannel();
var result = service.Version();

it all works well. That's not a perfect solution, since changes won't be picked up automatically, so may be there are other solutions?

P.S. an interface for a web service is now like:

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName = "BaseService.IBaseSvc")]
    public interface IBaseSvc2
    {
        [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IBaseSvc/Version", ReplyAction = "http://tempuri.org/IBaseSvc/VersionResponse")]
        [WebGet]
        VersionInformation Version();
    }
Community
  • 1
  • 1
Shaddix
  • 5,901
  • 8
  • 45
  • 86
0

You can achieve it by adding the protocols in config file

<webServices>
      <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
      </protocols>
</webServices>
HatSoft
  • 11,077
  • 3
  • 28
  • 43
  • This would allow POST methods, and should be done on server-side, yes? But I have no access to that service configuration, I have to consume GET's.. – Shaddix Oct 03 '12 at 09:00