Passing a custom object to a Windows Workflow WCF Service - c#

I'm having a problem passing an object for some reason and I'm not sure why. I'm getting a Object reference not set to an instance of an object error.
Essentially from my client application I make a call to a Windows Work...
Client Code
Workflow1Client client = new Workflow1Client();
ACME.Order newOrder = new ACME.Order();
newOrder.Property1 = "xyz";
//set all the other properties
string status = client.GetData(newOrder);
//**This is where object reference error occurs**
Proxy Expecting
public string GetData(ACME.Order NewOrder)
{
return base.Channel.GetData(NewOrder);
}
Workflow Code
[ServiceContract]
public interface IWorkflow1
{
[OperationContract]
string GetData(ACME.Order NewOrder);
// TODO: Add your service operations here
}
I'd appreciate any help on this. Also beyond this question is sending a Object (ACME.Order) good practice or should I be trying to tackle this a different way?
Thanks

I have run into this myself and in my case it was a Serialization error on the custom object. To be able to send a custom object across WCF it should have the [Serializable] attribute. To test, see if you can serialize the object to an XML file. If that fails the WCF transfer will not work.
Hope that helps.

Related

c# SOAP with service reference is not showing real response

I'm creating an UWP app, that needs to connect to asmx service. I've done that by using service reference, which works with TempConvert but not with my asmx service
This is how my code looks like
HelpdeskSoapClient HPsoapClient = new HelpdeskSoapClient();
getIncInput input = new getIncInput();
input.username = "450";
getIncResponse realresponse;
realresponse= await HPsoapClient.getIncAsync(input);
Debug.Write(realresponse);
but response is not an XML file or something else, but "DTS.helpdesk.getIncResponse"
Any clues ?
getIncResponse is the object that is returned by the service when you make the call.
When you pass realResponse into the Debug.Write, since it's an object, the base functionality of ToString() is called, which unless overridden in the object will return the fully qualified type name - i.e., DTS.helpdesk.getIncResponse.
You should be able to access the properties of the object to get the data, similar to how you set the username on the getIncInput object (input.username = "450";).
The temperature conversion service worked because it returns a simple type (string), not a complex type (getIncResponse). There is no error here.

How to consume WCF after passing C# class object

My WCF contains two methods. The first is simple which returns string and takes string as parameter, but in second method I am passing a class containing properties as parameter and return string.
When I comment second method then I am able to get WCF_Masters.ServiceClient object in client application but after uncommenting 2nd method I am unable to get that object.
I get only CompositeType instead of ServiceClient of My WCF service whose name is WCF_Masters.
Note that I am trying to consume WCF in WPF Windows application.
How can I get rid of this issue?
Edit
My WCF methods are:
public String GetMessage(string vName)
{
return "Hello world from " + vName;
}
public String SaveEmployee(EmployeeMasterSC vEmployeeMasterSC)
{
String mReturnMsg = string.Empty;
EmployeeMasterDAL vEmployeeMasterDAL = null;
vEmployeeMasterDAL = new EmployeeMasterDAL();
mReturnMsg = vEmployeeMasterDAL.SaveEmployee(vEmployeeMasterSC);
//mEmpDset.EmployeeData = Mdset; return mReturnMsg;
}
If I understood you correctly, you should not be adding a reference to your WPF DLL in your WCF service. Define the model in your service and then instantiate that model (by reference) in your WPF application, which is consuming the service.
I believe the reason it works when you comment out the 2nd method is that your 1st method has no reference to class structures defined in the WPF DLL.
Got the solution guys, It was the issue of database name I have Written incorrectly "AirportPortal" instead of "DB_AirportPortal" in WCF while inserting records into database

Why the result from the web service references and Service references are different?

I am bit curious about one thing which has happen while trying to understand the concept of Service References and Web Service References.
What I did is?
In my project I have added a web service as a Service Reference and trying to get my script run through the use of client.
But while getting result it is throwing an exception as in the following image:
I have tried to trace out the cause but not able to get the proper answer for that.
I have following code for the resultant object.
[
ComVisible(false),
Serializable,
SoapTypeAttribute("RecordList", "http://www.someadd.com/dev/ns/SOF/2.0"),
XmlType(TypeName="RecordList", Namespace="http://www.someadd.com/dev/ns/SOF/2.0")
]
public class MyRecordListWrapper
{
private IxRecordList recordList = null;
private const string XMLW3CSchema = "http://www.w3.org/2001/XMLSchema";
[SoapElement("Headers")]
public Header[] Headers = null;
[SoapElement("Records")]
public Record[] Records = null;
// some methods to work on intialization
public SmRecordListWrapper(ref IxRecordList p_RecordList)
{
recordList = p_RecordList;// record list initialization
Headers = CreateWrapperHeaders(); // will return header class object
Records = CreateWrapperRecords(); // will return record object
}
}
Can anyone tell me why this error is showing for me?
While adding reference as a Web Service Reference
when I add the same reference as a web reference that time the program is not showing any error and runs successfully?
So can anyone tell me what is the difference in working with the same code using service reference and web service reference?
and Which is a correct way to ass references?
Hope I will get some more described answers to make the things easy to understand.
Thanks in advance.
Adding a web reference, visual studio uses xsd.exe to generate the classes from the service metadata. This uses XmlSerializer under the hood.
Adding a service reference, visual studio uses svcutil.exe to generate the classes from the metadata. This uses DataContractSerializer under the hood.
Two separate tools, two outcomes. For general information, DataContractSerializer is a lot less forgiving when it comes to generating classes from metadata.

WCF deserialization returning 0 list elements

I'm having some problems with deserializing an object.
I have following classes:
Metadatastore:
[DataContract]
public class MetadataStore : IEnumerable<ItemMetadata>
{
private List<ItemMetadata> data = new List<ItemMetadata>();
private string folderPath = null;
[DataMember]
public string FilePath
{
// getter and setter
}
[DataMember]
public List<ItemMetadata> Data
{
// getter and setter
}
}
ItemMetadata:
[Serializable()]
public class ItemMetadata
{
// syncid, syncversion, uristring etc..
}
The problem:
I'm transferring a Metadatastore object from my server(which has a wcf service running) to my client by using an output parameter. So serialization/deserialization of this output param is automatically done by wcf I suppose.
This is what happens:
the client calls the service:
service.GetChangeBatch(out metadatastore_object, otherValue);
the server responds correctly (metadatastore_object is filled and serialized successfully -> no errors)
the object I receive on client side though is not correct: the FilePath is filled correctly, but the List Data object contains zero elements! I checked also on the server and the data list contained 2 elements. Another strange thing to note is that it isn't either null, it's just a newly created empty list.
Does somebody has some experience with this, I can provide more code if needed.
Thanks in advance. Greets Daan
Use CollectionDataContract instead of DataContract.
Here the msdn's explanation about CollectionDataContract:
http://msdn.microsoft.com/en-us/library/aa347850.aspx
It could be this line:
private List<ItemMetadata> data = new List<ItemMetadata>();
That is emptying your list.
Also I would have marked ItemMetadata with DataContract and all properties with DataMember.
The ItemMetadata class should also be decorated as a DataContract so that the client has knowledge of the type and how to deserialize it.
You can also enable detailed message logging on wcf service to see what SOAP xml is coming back from the server.
You can then figure out if client is not deserialising xml to object correctly or server is not serialising object to xml correctly.
HTH

how to send an object to C# WCF service from PHP using SOAP

I'm having trouble sending a custom object thats defined as a datacontract in my WCF web service from PHP. I'm attempting to accomplish this via SOAP.
Here is what the dataContract looks like:
[DataContract]
public class simplyCustomer
{
[DataMember]
public int id;
[DataMember]
public string name;
[DataMember]
public string contact;
[DataMember]
public string street1;
[DataMember]
public string street2;
[DataMember]
public string city;
[DataMember]
...
}
So I have a function that takes simplyCustomer as parameter on WCF service. The php can receive simplyCustomer just fine using another function that returns one. However, if I call the one that accepts it using this code in PHP:
$retVal = $simplyService->__soapCall("addCustomer",array('parameters'=>$params));
The SOAP envelope that this call generates leaves the object NULL causing the WCF service to complain about null reference.
Here is the envelope that is generated:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Body><ns1:addCustomer/></SOAP-ENV:Body></SOAP-ENV:Envelope>
The parameters should be where addCustomer is but there's nothing there.
Any help would be greatly appreciated!
Thanks!
I faced the same issue when building a private project.
My solution was to use T4 to generate service- and datacontract proxies, maybe you find it useful. Message me if you have any questions, the templates are not tested to their full extent.
You find the templates on github, including sample servicecontracts/datacontracts:
https://github.com/schaermu/wcf-phpclient-t4
feel free to fork the project!
cheers
Though this is asked while before, thought to add my input since I came accros the same issue.
Assuming your operation contract look something similar to
[OperationContract]
public <return_type> addCustomer(simplyCustomer parameters);
what you have suggested should work given that $params got all the required values set on initialisation where ever that has done and variable names are exactly similar to data contract.
Few tips going through this though.
1) If you have manage to send the object to the service, Could check the service logs to see what has gone wrong.
2) Just check your constructor to see all the parameters are set.
3) Also good to check that soap client is initialized and consumed properly.
eg : (following is, one of many possibilities)
$client = new Client( $baseUrl, array('soap_version' => SOAP_1_1,));
$result = $client->addCustomer(array("parameters" => $params ));
I had the same kind of problem. Cant see how you built your $params but I solved mine by doing this:
$username = "test";
$password = "test";
$input = array ("composite" => array("Password" => $password, "UserName" => $username));
$result=$client->__SoapCall('AuthenticateUser',array('parameters'=>$input));
My service method looks like this
[OperationContract]
AuthenticationData AuthenticateUser(AuthenticationData composite);
Using Fiddler is a good help when figuring out how to build your Soap stuff

Categories

Resources