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&amp;clcid=0x409"
            title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
    </p>
</asp:Content>

The only change here from the default Default.aspx is on line 7.

Click on “Add Service Reference”

Now click on “Advanced”

Now click on “Add web reference”

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)

Now the service is created.

Double click on Default.aspx.cs and instantiate class from the newly created service. Make sure that you will like it to the Web Reference name we used in step 5

Make request to the service and get the response into a string. Then change the HTML using InnerHTML to show the string content

Run the debugger or hit F5. At this point you should be able to see the response from the server.

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.