You are not logged in.

#1 13 Jul 2006 2:23 am

adri76
New Member
Registered: Jul 2006
Posts: 3

PHP Webservice accessed from .NET

Hi
I've got a webservice problem that I just cannot crack. I saw a article on sanity-free about accessing a PHP webservice from .NET and hope that someone can help me with this as it's driving me nuts.
I'm making use of an online SMS service to receive competition entries via SMS.
Once the SMS is received by the server it triggers a .NET webservice client to access a webservice and the "return" string from the webservice is then SMS'ed back to the sender.
The webservice takes the info sent by the webservice client and does a lookup in a MySQL DB to determine what is returned. This is all done via PHP. (no problem there)
The problem I'm having is that I cannot get the .NET client to communicate with my PHP (nusoap) webservice. I have established that the webservice is called, but it ends there and nothing happens. The .NET client was developed by the company that provides the SMS service and I have no control over it. I asked their tech support for help, but they say .NET cannot access a PHP webservice.


Please Help I know this can be done and it should be quite simple, but I cannot get it to work





Here is a Doc I got from them with the client spec and some guidelines:

Description
iMessage allows you to integrate with your custom application using web services. In order for iMessage to call and execute your web service in response to an SMS request, your web service needs to be constructed according to the specification below. Integration via web services requires development skills and a good understanding of web services.

Specification
To create a web service that can be accessed using the iMessage web service, implement a web service containing the following method:

Web method
Implement a single method called ProcessService (case sensitive), as described below.
•    Web method name:
o    ProcessService()
•    Return type:
o    string
•    Parameter list:
o    api_id: string (shortcode id - can be ignored)
o    timestamp: string (time of request)
o    from: string (originating cell phone)
o    too: string (short code)
o    text: string (active domain and sms text)

Target namespace and binding
You will need to set the target namespace and binding in your web service as
follows (see the code example below):
Class level attributes:
WebService Namespace="http://softcraft.co.za/webservices/"

WebServiceBinding
Name="SMSServiceSoap", Namespace="http://softcraft.co.za/webservices/"

Method level attributes:
WebMethod
SoapDocumentMethod Binding="SMSServiceSoap"

Disco file
If you have implemented your web service and iMessage cannot perform discovery, the disco file generated by your web service may contain namespaces that result in iMessage being unable to resolve the bindings. In this case, try the following:

Create a new disco file for integration with iMessage web services:
1.    Copy the following XML into a text file and rename to ‘yourFileName’.disco.
2.    Change the following attributes according to your web service location (the attributes are marked as http://..." in the current XML):
o    contractRef ref : supply the url for your WSDL file
o    contractRef docRef: supply the url for your web service
o    soap address : supply the url for your web service
3.    Place this disco file in the same folder as your WSDL file
4.    Reference this disco file from your iMessage web service (on the iMessage web site)

<?xml version="1.0" encoding="utf-8"?>
<discovery xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.xmlsoap.org/disco/">
  <contractRef ref="http://..." docRef="http://..." xmlns="http://schemas.xmlsoap.org/disco/scl/" />
  <soap address=http://..." xmlns:q1="http://softcraft.co.za/webservices/" binding="q1:SMSServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
</discovery>

Example
You have set up the domain 'bob' on iMessage short code 34050, with a web service attached. The web service returns a string, in our example, the greeting “Hello Bob”. The web service has the following hypothetical URL http://www.mydomain.com/tickets.asmx. The WSDL is referenced using the following hypothetical URL: http://www.mydomain.com/tickets.asmx?wsdl. You have set up the disco file using these URLs as described above and have placed the disco file at the following hypothetical URL http://www.mydomain.com/myservice.disco. You configure the iMessage service to point to the disco file.

A client (with cell number 27823951312) sends an SMS containing the word ‘bob’ to 34050. iMessage retrieves the disco file and dynamically locates and processes the web service, which returns “Hello Bob”. The greeting is automatically returned via SMS to 27823951312. If the web service returns an empty string, no SMS is sent.

Example code in C#
Use the following example code in C# to check how to set the binding and namespace for your web service. The following code implements the specification described above and returns “Hello Bob”.


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

using System.Web.Services.Protocols;

namespace MyTestWebservice
{

    [WebService(Namespace="http://softcraft.co.za/webservices/", Description="iMessage request.")]
    [WebServiceBinding(Name="SMSServiceSoap", Namespace="http://softcraft.co.za/webservices/")]
    public class TestService : System.Web.Services.WebService
    {
        public TestService()
        {
            //CODEGEN: This call is required by the ASP.NET Web Services Designer
            InitializeComponent();
        }

        #region Component Designer generated code
       
        //Required by the Web Services Designer
        private IContainer components = null;
               
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if(disposing && components != null)
            {
                components.Dispose();
            }
            base.Dispose(disposing);       
        }
       
        #endregion


        [WebMethod()]
        [SoapDocumentMethod(Binding="SMSServiceSoap")]
        public string ProcessService(string api_id, string timestamp, string from, string to, string text)
        {
           
            //            api_id: string (shortcode id - can be ignored)
            //            timestamp: string (time of request)
            //            from: string (originating cell phone)
            //            too: string (short code)
            //            text: string (active domain and sms text)
            return "Hello Bob";
        }
    }
}

Offline

 

#2 13 Jul 2006 1:36 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: PHP Webservice accessed from .NET

I'm absolutely positive that they can work together.  now whether nusoap can generate the websevice wsdl as they need it is another question.

I'll have to look at it a little later tonight. 

you might involve modifying nusoap a little bit.

what does your webservice look like (as far as server configuration, not how the method looks like).

Offline

 

#3 13 Jul 2006 10:12 pm

adri76
New Member
Registered: Jul 2006
Posts: 3

Re: PHP Webservice accessed from .NET

Hi
Here's my webservice config:

// Pull in the NuSOAP code
require_once('nusoap.php');

// Create the server instance
$server = new soap_server();

// Initialize WSDL support
$server->configureWSDL('SMSServiceSoap', 'http://www.thejobsite.co.za/webservice.php?wsdl');




// Register the method to expose
$server->register('ProcessService',                // method name
    array('api_id' => 'xsd:string','timestamp' => 'xsd:string','from' => 'xsd:string','too' => 'xsd:string','text' => 'xsd:string'),        // input parameters
    array('return' => 'xsd:string'),      // output parameters
    'http://www.thejobsite.co.za/webservice.php?wsdl',                      // namespace
    'http://www.thejobsite.co.za/webservice.php/ProcessService',                // soapaction
    'rpc',                                // style
    'encoded',                            // use
    'Post a test reply'            // documentation
);

Offline

 

#4 13 Jul 2006 10:15 pm

adri76
New Member
Registered: Jul 2006
Posts: 3

Re: PHP Webservice accessed from .NET

I tried using the namespace they specified, but it did not seem to make any difference, I only started looking at webservices about a week ago so please excuse my ignorance.

Offline

 

#5 13 Jul 2006 10:25 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: PHP Webservice accessed from .NET

yea I've been messing with it here as well.  nusoap is having a problem handling the type of soap encoding that the webservices are requiring.

one suggestion would be to wrap your php webservice with a C# client, and creating a C# webservice that your sms client can consume. (I can show you how to do this later if you need... I have to get to bed now)

either that or code the webservice in php all by hand (good luck it isnt easy, which is why I started looking for a php library to begin with).

Offline

 

#6 21 Jan 2008 11:58 am

sregan
New Member
Registered: Jan 2008
Posts: 4

Re: PHP Webservice accessed from .NET

Hello,

I am using VS 2008 C# and I have followed a few examples on the web using nusoap for PHP. I find your exmaple to be one of the best out there. But I have ran into a encoding problem and I was wondering if anyone knows of a fix for this problem. The message I get back is this:

The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (text/xml; charset=utf-8).

I think its VS 2008 but maybe I need to tell my PHP service something to change the response encoding from ISO-8859-1 to UTF-8?


FYI, I am just doing the simple test string Hello + $who example right now.


The full message returned is:

The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 483 bytes of the response were: '<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:ProcessSimpleTypeResponse xmlns:ns1="http://evemarket.mmobot.com"><return xsi:type="xsd:string">Hello Shawn</return></ns1:ProcessSimpleTypeResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>'.

As you can see the request is fine, but it is the reponse that is doesn't like....


TIA

Last edited by sregan (21 Jan 2008 12:01 pm)

Offline

 

#7 21 Jan 2008 4:36 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: PHP Webservice accessed from .NET

I know you can set the encoding using mb_internal_encoding("UTF-8"); in your PHP script (I'd put it in the same code that you place your server registration in)  but what I don't know is if nusoap uses this to build the xml element (which I'd imagine it does).  if it does, then this should make it work.

Offline

 

#8 21 Jan 2008 8:06 pm

sregan
New Member
Registered: Jan 2008
Posts: 4

Re: PHP Webservice accessed from .NET

It appear Nusoap doesn't use it to build the xml. I dropped it in and got the same repsonse. I will keep digging.....

Offline

 

#9 21 Jan 2008 8:12 pm

sregan
New Member
Registered: Jan 2008
Posts: 4

Re: PHP Webservice accessed from .NET

I thought this: $server->decode_utf8 = true;

would tell nusoap to encode in utf-8 but it doesn't appear to work or I am not reading it correctly.

Offline

 

#10 21 Jan 2008 8:14 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: PHP Webservice accessed from .NET

looks like the encoding is hard coded.  just out of curiosity can you able to consume the same service at http://zx.bindmaker.org/services/test.php?wsdl

I was able to add a web reference to it and invoke ProcessSimpleType without problems, though what it did return was exactly the same as what you posted.  I'll check around through  the source and see where all its hard coded.

Offline

 

#11 21 Jan 2008 8:25 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: PHP Webservice accessed from .NET

well, found it...


Code:

$server->soap_defencoding = 'utf-8';

will do it.

Offline

 

#12 22 Jan 2008 8:21 am

sregan
New Member
Registered: Jan 2008
Posts: 4

Re: PHP Webservice accessed from .NET

doh! That did it. Did you find that setting in the nusoap docs? I didn't even see it.

Thanks

Offline

 

#13 22 Jan 2008 9:03 am

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: PHP Webservice accessed from .NET

no I actually googled something (I forget what exactly now), and it brought up one of those sites that host source code for open source projects (linked to the nusoap source code).  I noticed in the link from google it showed the <?xml version="1.0" encoding="$this->soap_defencoding"?> code, so I searched for that in the link from google and saw where it was using it in soapSerialize, and figuring that was where it built up the soap message, I tried setting it and it worked.

Offline

 



© 2003 - 2017 NullFX
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License