Reputation: 31
I have to create an app that sends some data to a (SOAP)WebService and show its response. It seems simple but the problem is that after consuming the WS, the variable remains empty. I tried both C# and VB with no luck.
This is the code:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
CardifWS.RequestContactWsService webService = new CardifWS.RequestContactWsService();
string usuario = "user987";
string name = "teste2003 1552";
string cpf = "123456789";
string email = "[email protected]";
string zipCode = "04536010";
string city = "sao paulo";
string neighborhood = "itaim";
string state = "sp";
string address = "itaim";
string addressNumber = "98";
string addressComp = "2";
int dddPhone = 11;
string phone = "12345678";
int dddCellPhone = 11;
string cellPhone = "1187654321";
int fipeCode = 123456;
string chassi = "123456789";
string renavam = "987654321";
string placa = "abc3456";
string marca = "ford";
string modelo = "ka";
int colorCode = 456;
int anoFabricacao = 2010;
int anoModelo = 2011;
int indice = 1;
string[] parametros = "7".Split(' ');
string bestTimeCall = "T";
CardifWS.RequestContactResponse respuesta = webService.requestContact(usuario, name, cpf, email, zipCode, city,
neighborhood, state, address, addressNumber,
addressComp, dddPhone, phone, dddCellPhone,
cellPhone, fipeCode, chassi, renavam, placa,
marca, modelo, colorCode, anoFabricacao,
anoModelo, indice, parametros, bestTimeCall);
Console.WriteLine("Response: {0}", respuesta.ToString());
Console.WriteLine("errorCode: {0}", respuesta.errorCode.ToString());
Console.WriteLine("errorDesc: {0}", respuesta.errorDesc);
Console.WriteLine("id: {0}", respuesta.id.ToString());
Console.ReadLine();
}
}
}
And this is the WS URL
http://directsales2.uat.cardif.com.br:8080/autofacil-ws/services/RequestContactWs?wsdl
Using WireShark I know for sure that the WS is sending me the response, but some reason .NET seems to not be able to read it.
I´m using Visual Studio 2010
Upvotes: 3
Views: 1167
Reputation: 46
I checked the service and apparently the namespace for the response is different from the service namespace.
I used svcutil.exe to generate a proxy class for the webservice
SvcUtil.exe /o:c:\temp\foo.cs http://directsales2.uat.cardif.com.br:8080/autofacil-ws/services/RequestContactWs?wsdl
Import the class into your project, and add the service to the app.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="RequestContactWsSoapBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://directsales2.uat.cardif.com.br:8080/autofacil-ws/services/RequestContactWs"
binding="basicHttpBinding" bindingConfiguration="RequestContactWsSoapBinding"
contract="Cardif.Autofacil.WebService.RequestContactWs" name="RequestContactWs" />
</client>
</system.serviceModel>
After that you can change the namespace for the RequestContactResponse in the imported class
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace ="http://webservice.autofacil.cardif.com.br")]
public partial class RequestContactResponse
Upvotes: 1