将PEAR SOAP与WSDL连接到C#standalone .exe

I am trying to create a Web Service where parameters chosen from a web-page are sent to a standalone.exe written in C# which controls a CAD package installed on the server. The CAD package then generates an image based on the selected parameters chosen by the user on the front-end web-page. In a nut shell I need:

  1. User selects two parts
  2. Selected parts are sent to C# .exe
  3. C# runs CAD package, connects the parts, returns image of two parts
  4. User sees image

From what I understand, I need SOAP implementation with a visible WSDL. I had no problems running through tutorials and creating my own SOAP and WSDL and communicating on my local and remote servers between my own PHP functions.

Now I am trying to get a PHP written SOAP to be consumed by a C# standalone and that's where I am getting lost. I am relatively new to SOAP and WSDL but I understand the basics and functions of each. Additionally, I started using NUSOAP for my wsdl generation.

Is there a similar code package that allows the creation of WSDL files from c# methods that allow for SOAP connectivity?

Also, my client and the web page will always know the WSDL and the required parameters to be sent. Essentially, this is just a gateway between web and the CAD package.

Here is the Wheezly McDizzle

<?xml version="1.0" encoding="UTF-8"?>
<definitions
    xmlns:typens="urn:getBlockedIP"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    name="getBlockedIP"
    targetNamespace="urn:getBlockedIP">

  <types></types>

  <message name="getBlockedIP">
    <part name="idNumber" type="xsd:string"/>
  </message>

  <message name="getBlockedIPResponse">
    <part name="ipAddress" type="xsd:string"/>
  </message>

  <portType name="blockedIPPort">
    <operation name="getBlockedIP">
      <input message="typens:getBlockedIP" />
      <output message="typens:getBlockedIPResponse"/>
    </operation>
  </portType>

  <binding name="blockedIPBinding" type="typens:blockedIPPort">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name = "getBlockedIP" >
      <soap:operation soapAction = "urn:blockedIPAction" />
      <input>
        <soap:body namespace="urn:getBlockedIP" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>
      <output>
        <soap:body namespace="urn:getBlockedIP" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
    </operation>
  </binding>

  <service name="getBlockedIPService">
    <port name="blockedIPPort" binding="blockedIPBinding">
      <soap:address location="http://mysite.com/xdata/blockedip_api.php"/>
    </port>
  </service> 
</definitions>

The method that this is testing is a simple array fetch with a single parameter. It is just an array with 25 elements that contains blocked IPs and the user picks a number between 1-25 and the method spits out the IP related to that location in the array.

I mimicked the method in C# as a command prompt program with Console.WriteLine and Console.ReadLine(). (That is incorrect obviously as the C# program has to grab the parameters from the XML file rather that any user input)

So now I am stuck - my head is all jumbled up with WhizCheese Dulls and SOAP and XML. I am confused as to where to go from here. I am pro with front and back end Web development but still wet behind the ears when it comes to the .NET framework.

Essentially what I would like is someone to point me in the right direction to finally accomplish my first stated goal in this project. Is it even possible with the way i am doing things? Maybe SOAP is not the correct path? I am also getting confused as to how to send the parameters to a standalone c# .exe and have it consume it (like a hamburger...mmmmmmm).

Here is my soap instantiations in PHP on the remote server:

Client:

// WSDL location to be used with a WSDL instantiation of SOAP
$namespace = 'http://mysite.com/xdata/blockedip.wsdl';

// Parameters are easier sent as an array with associative keys
$params = array('arrayNum' => $number);

// include soap client (php.ini include_path set to installed PEAR location)
require_once 'SOAP/Client.php';

// create SOAP Client with an exposed WSDL location
$wsdl = new SOAP_WSDL($namespace);

//communicate with server, WSDL
$SoapClient = $wsdl->getProxy();

//call method with parameters
$ip = $SoapClient->call("getBlockedIP", $params);

Server:

// include soap server and create server object
require_once 'SOAP/Server.php';
$soapServer = new SOAP_Server();
$server->_auto_translation = true;

// create class with desired method
$blockedip = new SoapTestClass();

// add class and namespace schema
$soapServer->addObjectMap($blockedip, 'http://schemas.xmlsoap.org/soap/envelope/');

// respond with raw post
$soapServer->service($GLOBALS['HTTP_RAW_POST_DATA']);

If you need anything else, ill gladly share. Thank you for taking the time to read this and for any help you can offer! I Greatly appreciate it.

UPDATE:

From what i have been reading maybe i have to turn on metadata yet i have no idea where this can be done?

UPDATE:

I have been using NUSOAP to generate my WSDL files from php methods and connecting them to VISUAL STUDIO 2010 C# and they have been working. I am now stuck on reversing the process. I need php to send parameters to a C# method and have that .exe return something.

I went with a C# program that connects to MySQL and have it periodically check for new entries in a table.

Since it seems you are trying to generate the proxy - you need to enable metadata discovery, so the client program is aware of how to structure the call (parameters, methods, return value). Are you using Apache, IIS or something else?

What is Metadata Exchange Exposing Metadata via IIS Exposing Metadata via Apache

I updated links to enable metadata for both Apache and IIS - there may be better instructions out there - I've only dabbled in Apache.

There isn't anything "wrong" with SOAP it is just xml over http protocol, It can be a contract-first (think IDL for Web) method defining functions/services think IDL for the Web. There appear to be plenty of tools available in php to facilitate this. NuSoap is one such library to more easily manage - and Scot Nichol goes into great depth about setting this up. NuSoapIntro Also a code-sample modeled after this- Simple PHP sample CodeProject Technically, if you have the correct xml input format for the method - you could just HTTP POST the expected input (as defined by the WSDL) and it "just works". I've found SOAPUI as an indispensable tool for testing (I am not affiliated in anyway).

If SOAP is too much heartache you may consider going the RESTful approach REST Frameworks Php It will use more of a URL-based method signature for your external interface and may be easier to implement your goal.

(Ah - WAMP over LAMP)

It's not entirely clear what your question is, but it sounds like you are trying to get your c# application to provide the wsdl. The php can then use the exposed contract.

The WCF (window communication framework) portion of the .NET library supports this. In particular the SessionHost class will provide a server that can host the SOAP service and expose the WSDL.

First you need to define your contracts in c#. You do this by creating an interface with the DataContract attribute.

Example interface defining contract.

[ServiceContract]
public interface MyContract
{
    [OperationContract]
    void MyOperation(string param1, int param2);

    [OperationContract]
    void MyOtherOperation(int param1, out int outputParam);
}

You can then create a service host which will create a SOAP server and tie the incoming requests to a class that implements your interface. It will also expose the WSDL file for you.

To set up a host.

// create service host
// Note: ServiceHandler is a class you make that implements your service contract interfaces
ServiceHost host = host = new ServiceHost(typeof(ServiceHandler), new URI("127.0.0.1");

// enable metadata exchange (creates wsdl URL)
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);

// start the host listening
host.Open()

Hope that helps to get you started.

I'm working on an analogous issue. I went through all manner of permutations, and came to the conclusion that WDSL/XML weren't the best solution.

Here's what I came up with: AJAX. Push the web page request to the standalone C# code. It then pushes the requisite graphics out (preferably in a PNG or JPEG). That, in turn, gets put into an HTML element for display.