I noticed that there are a lot of questions about consuming a SOAP service from a PHP Server with a .Net client created by Visual Studio, so I decided to put some light on the subject. It looks like Visual Studio has moved some parts of the menu, and MS deprecated the SOAP endpoints in favor to Windows Communication Foundation.
Unfortunately there are still people trying and wanting to use SOAP, so I show how I manage to create .Net client in Visual Studio 2010 for PHP SOAP Server using Zend AutoDiscovery class.
First we start by creating a new web project:
File->New Project->ASP.NET Web Application
Now we need to make some preparations in order to see the response from the SOAP server.
Open the Default.aspx and change it to the following:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication17._Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <h2 id="q1" runat="server"></h2> <p> To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>. </p> <p> You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409" title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>. </p> </asp:Content>
Now type the URL in the box and hit the green arrow. That should bring back all the available methods for the service. Make sure that you change the “Web Reference Name” to something simple like “Service” and remember the namespace of the service – in my case this is “Model_ServiceService” (Not too descriptive, I know)
I noticed a couple of problems when using .Net client on PHP Server though:
The document encoding should be “literal”
and you cannot use “complexType”.
I was forced to use only primitives (mostly strings) and convert all the complex structures into jSON or XML serialized strings in order to parse them in VS.