C# Console App SOAP response is null - c#

I've seen some questions very similar to mine, but they seem to be a few years old now, and I'm not sure if the same fixes apply.
Basically I have access to a SOAP service. I've added it as a Service Reference in my C# console app. I can establish a connection, but need a session ID before I can do anything. The Session ID is part of the response, but the response in C# is null. I've used Fiddler, and I can see that I'm successfully making a connection, and the response ID is there, but I can't get it to show in Visual Studio. Obviously the response is XML. Am I missing something? How do I capture that XML response in VS?
Thank you in advance.

Generally, at least in my experience, SOAP services return typed data. It will be defined by the service as string, datatable, etc. You need to determine the datatype and store the output from the SOAP service into that type.
Example:
string
string mystring = soapservice.getmystuff()
datatable
DataTable mydatatable = soapservice.getmystuff()
Then, once you have successfully stored the results in a typed object, manipulate that object to retrieve your data.

Related

Using WCF-Custom to process a tableop select query returns the original message.. not data

I've created a message with this syntax which was created by the schema.
My orchestration takes the message in and passes it to a Request/Response send shape. The response results are then passed to a Send port. I created my Soap Action header using the configuration created by the generated file. The action header throws a warning, but there are no errors. When I check the response folder it contains the original input message as shown above. It acts like its not even hitting SQL Server. Does anyone have any insight on how to fix this. I've built an insert application also, and it works fine.
Stupid mistake. I assumed that a send/response was two operations. Select and SelectResponse. Once I changed the SoapActionHeader to: TableOp/Select/dbo/M351SR it worked. thanks for the help

How to receive JSON data in ASMX web service

I'm trying to write an ASMX web service to receive a block of JSON data from elsewhere (meaning I have no control over the format of the data - it's documented and consistent, but outside my control). As a test, I've created a simple webpage that sends that same data via an AJAX request. The data is definitely attached as the payload of my POST request:
Picture of chrome devtools showing payload
But when I try to receive that data in my ASMX webservice, I get an empty string:
[WebMethod]
public string UpdateProjectImage()
{
using (var sr = new System.IO.StreamReader(HttpContext.Current.Request.InputStream))
{
string json = sr.ReadToEnd(); // this comes out as an empty string!
return json;
}
}
Please note that this is being built with VS 2012 and IIS 7.5 running on Win2008R2, and I cannot change the technology stack.
The streamreader technique ought to work, because I copied it from another webservice that's working - but it doesn't work in this case (it just gives me an empty string), and I don't know why. It's probably some weird configuration setting, but I just don't know what setting it might be.
Apparently I have to set sr.BaseStream.Position = 0 before the call to sr.ReadToEnd(). I'm not 100% it's the "right" solution (I've done this elsewhere and I didn't need to set the position, and it just seems weird to have to do that), but it's working now and that's good enough for me.
Special thanks to Jasen for pointing me in the right direction.

Reading FIlemaker XML with C# WebRequest

I am trying to use FileMaker's XML WebPublishing feature. When I try to request a database from filemaker via Mozilla I get a user/pass request..when I enter that info the XML file loads. When I try this on IE, I get a blank result.
I then tried to use c#'s webrequest function to load the URI and I am getting a blank result when using the network credentials, when i omit the credentials I get a 401 unauthorized error (expected); I can't seem to figure out why I am getting a blank result.
I'm not sure if this will work, but have you tried inserting the credentials into the URL?
http://user#password:server.company.com/fmi/xml/fmresultset.xml?-db=...
There was a same question, how to get data from FileMaker database. I know 3 solutions:
1. FileMaker php Api. Use to create web service between database and your application
2. FileMaker XML Api. It's easier than first solution, and no need know php.
3. Now open sourced RESTfm project that uses XML and php api's and create a simple web service to fetch data in JSON format.
Hope it will help you.

Interesting Issue found when using WCF Data Service Client Library to query data from a WCF Data Service

I have a simple data model with 3 tables (Account, Contact, and User) with the following relationships:
User -> Account (1 - Many) Account -> Contact (Many - 1)
I am exposing my data via an OData (v3) WCF Data Service, which is consumed by a .NET client that uses the WCF Data Service Client Library. I used the Add Service utility to generate the client proxy code to call the data service.
All methods in the client class uses the class's single DataServiceContext object for calling the web service. i.e.:
DC.WhEntities svcClient = new DC.WhEntities(new Uri(BaseUrl));
What I am having a hard time trying to figure out is why the same query request to the service starts failing after the 6th time. I have literally tried all possible ways to construct a call to the data service:
First approach:
DataServiceQuery<DC.User> users = svcClient.Users.Expand("Accounts");
QueryOperationResponse<DC.User> response = users.Execute() as QueryOperationResponse<DC.User>;
var user = response.FirstOrDefault(u => u.Id == long.Parse(key.ToString()));
Second approach:
string queryString = string.Format("Users({0}L)?$expand=Accounts", key.ToString());
foreach (var user in response) {...}
The last statement in both of the above solution starts failing with a message below after it has executed successfully 6 times in a row:
The response payload is a not a valid response payload. Please make sure that the top level element is a valid Atom element or belongs to 'http://schemas.microsoft.com/ado/2007/08/dataservices' namespace.
**StackTrace:**
at System.Data.Services.Client.Materialization.ODataMaterializer.CreateODataMessageReader(IODataResponseMessage responseMessage, ResponseInfo responseInfo, Boolean projectionQuery, ODataPayloadKind& payloadKind)
at System.Data.Services.Client.Materialization.ODataMaterializer.CreateMaterializerForMessage(IODataResponseMessage responseMessage, ResponseInfo responseInfo, Type materializerType, QueryComponents queryComponents, ProjectionPlan plan, ODataPayloadKind payloadKind)
at System.Data.Services.Client.DataServiceRequest.Materialize(ResponseInfo responseInfo, QueryComponents queryComponents, ProjectionPlan plan, String contentType, IODataResponseMessage message, ODataPayloadKind expectedPayloadKind)
at System.Data.Services.Client.QueryResult.ProcessResult[TElement](ProjectionPlan plan)
at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
When this happens, my WCF Data Service just stopped working and returns a response with
error on line 1 at column 83: Unescaped '<' not allowed in attributes values.
I am not sure if I am missing anything fundamental or if I'm constructing the WCF Data Service Client request incorrectly or if there is something on the WCF Data Service side that doesn't like the same client requesting the same thing more than 6 times.
I've already spent a few days and I meant 3+ days trying to figure this out. I am new to WCF Data Service and I thought I could learn from this tutorial, but so far I got more pain than gain.
I am experiencing similar issue, suddenly my server started (maybe some updates inflicted this, yet the cause is unknown) to return bad responses. If I start my server it works for some time, lets say responds to few requests in a normal manner and then starts to break xml structure of the OData feeds, resulting in <, hexadecimal value 0x3C, is an invalid attribute character. Line 2, position 72. exception.
SOLUTION:
I solved the problem by following this feed
If you have WCF tracing configured, make sure logMessagesAtTransportLevel="false" is turned off, otherwise you will experience this issue.
I tried setting logMessagesAtTransportLevel to false and still got the error.
Then i remembered seeing this issue before when I had an assembly conflict. I went and created a brand new service and this solved my problem even when I had logMessagesAtTransportLevel set to true on my client. This ensured me that the problem was the service.
Although my solution solved my problem, I still don't know the exact issue and I already ran out of time to find it out. However, It is good to see that people are willing to help out and I truly appreciate the effort.
Thanks everyone again for your help.
Qster123.

.net Client consuming Axis2 Web Service

I have an .net 2.0 C# client app that has a web service reference to an Axis2 Java Webservice.
The idea is to send some xml data to the webservice, so it can be parsed and inserted into database.
The WS method accepts a single parameter of type 'xsd:anytype'.
Java web service:
public class JWS{
public Response AddData(Object inputXML) {
return Response;
}
}
C# Client:
JWS client = new JWS();
object inputXML = "<xml>some xml data</xml>";
response = client.AddData(inputXML);
There are 2 issues i am seeing when monitored using fiddler.
1) The request has an additional element '<inputXML>' added before the actual xml data.
<inputXML><xml>some xml data</xml></inputXML>
2) The xml is encoded, so '<' is appearing as "<"
I am not sure if this is how SOAP request's are generated but i would like to remove the <inputXML> tag and also, have the xml appear as is without having to replace the special characters.
Is this possible? Is it got something to do with 'Wrapping'/'UnWrapping' Types?
Also, i have used SoapUI to test the java web service and it works well. However, in the request tab, i had to manually remove the <inputXML> tag and submit for it to work correctly. Please help.
TIA
This is expected behaviour under SOAP and the inputXml variable will be decoded back to the original string when passed to your web service method.
However this may indicate a problem with your design, have you considered constructing an object to send to your web service rather than xml data? (As this object will transparently be converted to xml for the web service call anyway).
I found out that the issue is not with encoding but it was interpreted incorrectly on java side when the message was viewed in axis2. So, it is getting decoded properly. Also, the inputxml is now being handled correctly.

Categories