ASP.net client consuming a NuSoap web service

Last post 07-04-2009 4:34 AM by johnwsaunders3. 6 replies.

Sort Posts:

  • ASP.net client consuming a NuSoap web service

    02-02-2007, 3:53 PM
    • Member
      point Member
    • mnavasca
    • Member since 02-02-2007, 8:40 PM
    • Posts 3

    Hello,

    I'm trying to create a ASP.net client to consume a NuSoap service that I've created but for some reason I can't get it to work.

    I used this tutorial for creating both the NuSoap service and the ASP.net client and have followed all the instructions exactly. In other words I get the expected page on the service side and when I add a new web reference to my .net client I get the necessary proxy classes to access and run the service.

    My ASP.net/C# code looks like this:

     

    try
    {
      // the nusoap service
      TestService service = new TestService

    // try to use one of the service's methods. A WebException is thrown here when the client runs string msg = service.TestPrint("Welcome");

    // display message on the page testLabel.Text = msg; } catch(WebException ex)
    {
    // the error message displayed is a 301 (moved permanently) page pointing to
    // http://mnavasca.ca/TestService/Server.php
    testLabel.Text = ex.Message; }
      

    I have tested the service with a NuSoap client and a Java AXIS client and the service works with both (as expected).
    The wsdl file is located at http://mnavasca.ca/TestService/Server.php?wsdl which validates with various online wsdl-validating tools

    Any help would be appreciated

  • Re: ASP.net client consuming a NuSoap web service

    02-06-2007, 6:00 PM
    • Member
      8 point Member
    • aMadHatter
    • Member since 01-10-2007, 7:47 AM
    • Dallas
    • Posts 5

    post your service and type registration php code.

     what errors are you getting in .net?

  • Re: ASP.net client consuming a NuSoap web service

    02-07-2007, 10:16 AM
    • Member
      point Member
    • mnavasca
    • Member since 02-02-2007, 8:40 PM
    • Posts 3

    Thanks for the reply

    I'm not getting any errors in my error log file. When I print a stack trace the exception is thrown at this line:

     

    System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) - methodName not found

     
    The NuSoap (PHP) service code:

     

    1
    2        
    3
    4 // NuSoap API 5 require_once('nusoap.php');
    6
    7 // Customers API 8 require_once('CustomerAccess.php');
    9 require_once('Customer.php');
    10
    11 // create the server instance 12 $webServer = new soap_server();
    13
    14 $namespace = 'http://localhost/MacpellWebService/Server.php?wsdl'; 15 $webServer->configureWSDL('MacpellWebService');
    16 $webServer->wsdl->schemaTargetNamespace = $namespace;
    17
    18 // our individual customer type 19 $webServer->wsdl->addComplexType
    20 (
    21 '
    Customer',
    22 '
    complexType',
    23 '
    struct',
    24 '
    all',
    25 '',
    26 array( '
    CustomerID' => array('name' => 'CustomerID', 'type' => 'xsd:int'),
    27 '
    LastName' => array('name' => 'LastName', 'type' => 'xsd:string'),
    28 '
    FirstName' => array('name' => 'FirstName', 'type' => 'xsd:string'),
    29 '
    Address' => array('name' => 'Address', 'type' => 'xsd:string'),
    30 '
    City' => array('name' => 'City', 'type' => 'xsd:string'),
    31 '
    Province' => array('name' => 'Province', 'type' => 'xsd:string'),
    32 '
    PostalCode' => array('name' => 'PostalCode', 'type' => 'xsd:string'),
    33 '
    PhoneNumber' => array('name' => 'PhoneNumber', 'type' => 'xsd:string'))
    34 );
    35
    36 // our customer array type 37 $webServer->wsdl->addComplexType
    38 (
    39 '
    Customers',
    40 '
    complexType',
    41 '
    array',
    42 '',
    43 '
    SOAP-ENC:Array',
    44 array(),
    45 array(array('
    ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:Customer[]')),
    46 '
    tns:Customer'
    47 );
    48
    49
    50 // register all the functions 51 $methodName = '
    AddNewCustomer';
    52 $input = array('
    customerInfo' => 'tns:Customer');
    53 $output = array('
    return' => 'xsd:boolean');
    54 $soapAction = false;
    55 $style = '
    rpc';
    56 $use = '
    encoded';
    57 $description = '
    A web service to add a new customer';
    58 $webServer->register($methodName, $input, $output, $namespace, $soapAction, $style, $use, $description);
    59
    60 $methodName = '
    DeleteCustomer';
    61 $input = array('
    customerID' => 'xsd:int');
    62 $output = array('
    return' => 'xsd:boolean');
    63 $soapAction = false;
    64 $style = '
    rpc';
    65 $use = '
    encoded';
    66 $description = '
    A web service to delete a customer';
    67 $webServer->register($methodName, $input, $output, $namespace, $soapAction, $style, $use, $description);
    68
    69 $methodName = '
    EditCustomer';
    70 $input = array('
    customerID' => 'xsd:int', 'customerInfo' => 'tns:Customer');
    71 $output = array('
    return' => 'xsd:boolean');
    72 $soapAction = false;
    73 $style = '
    rpc';
    74 $use = '
    encoded';
    75 $description = '
    A web service to edit a customer';
    76 $webServer->register($methodName, $input, $output, $namespace, $soapAction, $style, $use, $description);
    77
    78 $methodName = '
    GetCustomer';
    79 $input = array('
    customerID' => 'xsd:int');
    80 $output = array('
    return' => 'tns:Customer');
    81 $soapAction = '
    localhost/MacpellWebService/Server.php';
    82 $style = '
    rpc';
    83 $use = '
    encoded';
    84 $description = '
    A web service to get a customer';
    85 $webServer->register($methodName, $input, $output, $namespace, $soapAction, $style, $use, $description);
    86
    87 $methodName = '
    GetAllCustomers';
    88 $input = array();
    89 $output = array('
    return' => 'tns:Customers');
    90 $soapAction = false;
    91 $style = '
    rpc';
    92 $use = '
    encoded';
    93 $description = '
    A web service to get all customers';
    94 $webServer->register($methodName, $input, $output, $namespace, $soapAction, $style, $use, $description);
    95
    96 $methodName = '
    SearchForCustomers';
    97 $input = array('
    lastName' => 'xsd:string');
    98 $output = array('
    return' => 'tns:Customers');
    99 $soapAction = false;
    100 $style = '
    rpc';
    101 $use = '
    encoded';
    102 $description = '
    A web service to search for customers by last name';
    103 $webServer->register($methodName, $input, $output, $namespace, $soapAction, $style, $use, $description);
    104
    105 $methodName = '
    TestPrint';
    106 $input = array('
    message' => 'xsd:string');
    107 $output = array('
    return' => 'xsd:string');
    108 $soapAction = false;
    109 $style = '
    rpc';
    110 $use = '
    encoded';
    111 $description = '
    A test print method';
    112 $webServer->register($methodName, $input, $output, $namespace, $soapAction, $style, $use, $description);
    113
    114 $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
    115 $webServer->service($HTTP_RAW_POST_DATA);
    116
    117
    118
    119 // our functions 120 function AddNewCustomer($customerInfo)
    121 {
    122 $customer_db = new CustomerAccess();
    123 $customer = GetCustomerObject($customerInfo);
    124 return $customer_db->AddNewCustomer($customer);
    125
    126 }
    127
    128 function DeleteCustomer($customerID)
    129 {
    130 $customber_db = new CustomerAccess();
    131 return $customer_db->DeleteCustomer($customerID);
    132 }
    133
    134 function EditCustomer($customerID, $customerInfo)
    135 {
    136 $customber_db = new CustomerAccess();
    137 return $customer_db->EditCustomer($customerID, GetCustomerObject($customerInfo));
    138
    139 }
    140
    141 function GetCustomer($customerID)
    142 {
    143 $customer_db = new CustomerAccess();
    144 return GetCustomerArray($customer_db->GetCustomer($customerID));
    145 }
    146
    147 function GetAllCustomers()
    148 {
    149 $customer_db = new CustomerAccess();
    150 $allCustomers = array();
    151 $customers = $customer_db->GetCustomers();
    152 for ($i = 0; $i < count($customers); $i++)
    153 $allCustomers[$i] = GetCustomerArray($customers[$i]);
    154
    155 return $allCustomers;
    156 }
    157
    158 function SearchForCustomers($lastName)
    159 {
    160 $customer_db = new CustomerAccess();
    161 $matchingCustomers = array();
    162 $customers = $customer_db->SearchForCustomers($lastName);
    163 for ($i = 0; $i < count($customers); $i++)
    164 $matchingCustomers[$i] = GetCustomerArray($customers[$i]);
    165
    166 return $matchingCustomers;
    167 }
    168
    169 function TestPrint($message)
    170 {
    171 return "This is a message: " . $message;
    172 }
    173
    174
    175
    176 // our supporting functions 177 function GetCustomerObject($customerInfo)
    178 {
    179 $customer = new Customer($customerInfo['
    LastName'], $customerInfo['FirstName']);
    180 $customer->SetCustomerID($customerInfo['
    CustomerID']);
    181 $customer->SetAddress($customerInfo['
    Address']);
    182 $customer->SetCity($customerInfo['
    City']);
    183 $customer->SetProvince($customerInfo['
    Province']);
    184 $customer->SetPostalCode($customerInfo['
    PostalCode']);
    185 $customer->SetPhoneNumber($customerInfo['
    PhoneNumber']);
    186
    187 return $customer;
    188 }
    189
    190 function GetCustomerArray($customer)
    191 {
    192 $customerArray = array();
    193
    194 $customerArray['
    CustomerID'] = $customer->GetCustomerID();
    195 $customerArray['
    LastName'] = $customer->GetLastName();
    196 $customerArray['
    FirstName'] = $customer->GetFirstName();
    197 $customerArray['
    Address'] = $customer->GetAddress();
    198 $customerArray['
    City'] = $customer->GetCity();
    199 $customerArray['
    Province'] = $customer->GetProvince();
    200 $customerArray['
    PostalCode'] = $customer->GetPostalCode();
    201 $customerArray['
    PhoneNumber'] = $customer->GetPhoneNumber();
    202
    203 return $customerArray;
    204
    205 }
    206
    207 ?>
      
  • Re: ASP.net client consuming a NuSoap web service

    02-07-2007, 11:35 AM
    • Member
      8 point Member
    • aMadHatter
    • Member since 01-10-2007, 7:47 AM
    • Dallas
    • Posts 5

    looks like you've referenced the services as http://www.mnavasca.ca but you're host requires http://mnavasca.ca so when you post to http://www.mnavasca.ca/TestService/Server.php your web server is telling you that the location of that host is http://mnavasca.ca/TestService/Server.php

     

    try changing your namespace without the www.

  • Re: ASP.net client consuming a NuSoap web service

    02-09-2007, 2:18 PM
    • Member
      point Member
    • mnavasca
    • Member since 02-02-2007, 8:40 PM
    • Posts 3

    i got things working... it was a NuSoap issue rather than a .net one 

     

    thanks for the help anyways... 

  • Re: ASP.net client consuming a NuSoap web service

    07-01-2009, 10:47 AM
    • Member
      145 point Member
    • Wells
    • Member since 05-17-2006, 7:04 AM
    • Posts 57


    I have error while consuming NuSoap web service from csharp.

    This is my sample web service:

    http://rhinosubmitws.rhinodirectory.com/server3.php

    http://rhinosubmitws.rhinodirectory.com/server3.php?wsdl


    This is my php server code:



    <?
    // NuSoap API
        require_once('lib/nusoap.php');
        		
       	
       	// create the server instance
       	$webServer = new soap_server();
       	
       	$namespace = 'http://rhinosubmitws.rhinodirectory.com/server3.php?wsdl';
       	$webServer->configureWSDL('ws');
       	$webServer->wsdl->schemaTargetNamespace = $namespace;
       	
          	
       	$methodName = 'TestPrint';
       	$input = array('message' => 'xsd:string');
       	$output = array('return' => 'xsd:string');
       	$soapAction = false;
       	$style = 'rpc';
       	$use = 'encoded';
       	$description =  'A test print method';
       	$webServer->register($methodName, $input, $output, $namespace, $soapAction, $style, $use, $description);
    
    
      	
      	$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; 
      	$webServer->service($HTTP_RAW_POST_DATA);
    
      	
      	function TestPrint($message)
     	{
      		return "This is a message: " . $message;
      	}
    
     	
    ?>





    However when I try to call from .NET client, I have this error:

    "Client found response content type of 'text/html', but expected 'text/xml'."

    I can run the code without error in my localhost (Windows Vista with apache and php5)

    But when I upload the code to my server, I am always having this error message.

    Any idea?

    Thanks



  • Re: ASP.net client consuming a NuSoap web service

    07-04-2009, 4:34 AM

    If the server is sending you HTML, then I recommend that you read it. Use a tool like Fiddler to see what is being sent to you.

    John Saunders
Page 1 of 1 (7 items)