How to build a WCF service that consumes data given an XSD - wcf

I have been provided an XSD and a sample Xml file that contains the results I will be getting.
I am to build a Web Service that accepts this data and enter into a SQL 2005 table. Each time my service is invoked, I am expecting 1200+ rows of data.
I have also been provided two Xml files, success.xml and failure.xml, that are responses I am to provide back to the caller?
I would like to build a WCF service on the .Net 4.0 framework with one 'MethodToCall'. The other party would call this web service and pass in the data.
I used the SVCUTIL.exe file.xsd /dconly /importxmltypes to get an output.cs file.
Now what do I do?
How do I iterate through the rows to add to my table?
With so many rows, will I run into issues of having my service timeout or something?
Can I do the table insert/update in a batch after disconnecting from the wire?
Any sample or pseudo code would be appreciated.

How do I iterate through the rows to add to my table?
usually it generates classes using List for sequences in XSD, so you can iterate using foreach.
With so many rows, will I run into issues of having my service timeout
or something?
There are settings of binding like
<readerQuotas
maxDepth=""
maxStringContentLength=""
maxArrayLength=""
maxBytesPerRead=""
maxNameTableCharCount="" />
consider to increase its values.
Can I do the table insert/update in a batch after disconnecting from
the wire?
Think again, do you really need it? You should send response to sender that data is successfully processed. But you are going to send the response before data is written to the database. It could cause problems.

if the xml you got is not a soap envelope than you cannot build a wcf service that gets exactly it. you can build a service that gets that xml wrapped inside soap. that may or may not be what you want. to build a service that gets exaclty this xml use asp.net web api.
to build a wcf service given an xsd (and considering the limitation above) use wscf.blue.

Related

I'm testing a WCF Service and an EF Data layer, receiving String columns as (null), but receive integers as real data. Why are the strings null?

I'm building a multi-layered Windows VS C# solution that has a WCF Service Library project with EF6.2 loaded, and an ADO.NET Data layer with EF6.2 also.
The EDMX model is built as a 'database first' set of tables from my MSSQL Server Express 2016 server on my laptop. My WCF Service Interface and code
only have properties and methods for one of the tables at this point. And that table has also been built out in logic and data layer methods.
So, I'm testing that service now with the WCF Test Client, and I'm receiving some integer data correctly in my service's response from to the data layer, but no string data.
While testing my "GetMemberByID" method, it returns all String column results as a value of "(null)", and a type of "NullObject",
but returns Integers with their actual value. The WCF Soap response shows the returned String values as "". But,
the integers are returned like this: "7". There are over 50 data rows in my test database which is used as the source
for the EF6.2 EDMX build. My App.config's in data and service layers are referencing the same (localdb)\ V13.0 server and database.
Has anyone had this issue, and can you tell me what I'm missing? The MSSQL database was originally an (OleDb) MS Access database and I imported it into
MSSQL Server. Thanks in advance.
It seems that there is something wrong with the serialization process. On my side, the string field can be returned properly. By default, the DataContractSerializer is used to deserialize/deserialize the complex object data.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts
The most possible reason might be that the nullable field is not decorated by the [DataMember] attribute. Please check if the column of the DataContract autogenerated on the client-side contains the [DataMember] attribute.
http://sivakrishnakuchi.blogspot.com/2010/05/troubleshoot-wcf-service-returning.html
Feel free to let me know if the problem still exists.
Okay, I found my mistake. When translating the business domain objects back to the Service objects in the Service.cs code file, I was only translating the MemberID and the RowVersion - and no other columns. So, the only thing that was showing up in the WCF Test Client result was the MemberID and the RowVersion - which happen to be the only two non-strings in my entity. All the string types were null because I was not translating them back into the Service. Thanks for taking a look at this, Abraham, but you made me start looking closer, and thanks for the advice. The MS Documentation was helpful, too. Once I did a full "step into" debug trace from the UI through to the Data Layer and back, I was able to see the data translation failure. One more thing, before I could debug step by step all the way to the Data layer and back to the Service layer, I had to fix my "Underlying database did not open" issue that so many have had. I'm hosting my service through my local IIS, and had to make a few changes to the IIS application concerning the user credentials. My App.config is set to use "Integrated Security=True" - which is a "passthrough" credential in the IIS App pools. I had my IIS App set to "Specific User", but was not using a UserID/Password in my Connection String. Once I changed my IIS App to "Passthrough" - I was able to connect, and to debug to the DAL and back.

Wcf service - request and response data

What is the easiest way to see the input data elements and output data elements of a wcf service? (going through wsdl will be time consuming due to multiple type references) For ex. I can use soapUI to see the input data elements, but I have to know what input data should be provided to execute it and see the the output data elements. Is there any tool that can take the wsdl and provide a clean view of input and output schemas?
You can use a tool such as svcutil.exe or the "Add Service Reference" dialog in Visual Studio for that. You'd point the tool to the WSDL, and it woill generate classes with the contract defined by the WSDL. The code, even though it's auto-generated, is fairly readable.

Consume more than one WCF service in same orchestration

I need to consume two WCF services in the same orchestration.
I use the "Consume WCF Service Wizard" that generates the xsd, xml, messages, pots and a orchrestation for each service
The thing is I can't use all the multipart messages generated just in one orchestration, I just can use the ones from the service it was generated from
I think it might have a simple solution.
I would recommend that you create a separate "Schemas" Project for the schemas and bindings generated by the Wizard.
Reference this Project from your "Orchestrations" project and re-create multi-part messages for the schemas.
You don't need to use the auto-generated multi-part messages as you can create your own;
Just create a request multi-part message with a Body and set the message type to the appropriate schema in your referenced Schema project.
This is the most flexible way I can think of to achieve your objective.
HTH

Transfer XML between systems with Biztalk and WCF

I have system A which produces an xml-file and system B which takes the file. How can I implement this exchange using Biztalk with WCF?
You have two possible different solutions as I see it and it basically comes down to how typed you WCF service needs to be.
Do you need to transform you message into a new format? Or are you planning to use other features in BizTalk as content based routing etc? Are you at all interested in the content of the message while in BizTalk are you OK with just passing it thru?
If you are looking for a solution with the capabilities as described above you'll need to get the schema for the XML message you want to receive into WCF service and publish that service. Once the message is in BizTalk it's then typed and you can do what ever with it using BizTalk.
If you however just want to pass it thru you could just publish a service that received as message of type XML document and pass that thru. Here's a good post describing the a few different techniques to create a generic service accepting any XML as input.

Add Service Reference "___ is already defined"a

I have a WCF web service that I am working on and I built it and was delighted to find that I could use complex types in it. I added some and then realized that they were still not useable as those types on the client end. This is an internal web service so these types are known on both sides. Anyway, that's not the problem, as I took the complex types out, but I think it may have left some residual issues.
When I then changed my additions to all be base types (string, date, int, etc) then added the web service to the client project, I got a "[enumtype] is already defined" error. It occurred in the reference.cs file so I opened it up. Sure enough there were duplicate enums. Plus there were a bunch of helper (serializing) functions. The duplicate enum was from code that had been in there before I picked this web service up to work on. It had not caused an issue previously.
I opened up the reference.cs for the previous (successful) service reference. It did not have the duplicates or functions and also I noticed a difference between the entries that were in there. The reference.cs that was failing to compile had this additional attribute in several places:
[System.ServiceModel.XmlSerializerFormatAttribute()]
I also see that my new failed code was using string[] and the old was using ArrayOfString. I did not intentionally change this, but must have somehow set something differently in the process.
Does anyone have a few clues?
Thanks!
Have you tried deleting the service reference from the project and re-adding it? You may have to manually remove some (or all) of the serviceModel contents too. If that is the only Service Reference then definitely remove the serviceModel element contents too.
Once its all gone, re-add the Service Reference. If you're still having problems then it may be that the service metadata is generating invalid WSDL causing the duplicate enums.
UPDATE: Just for verifying the WSDL is not valid, you could try creating the service proxy manually using the SvcUtil command line utility. It generates your proxy code like Visual Studio does and may give you more troubleshooting info.
After a lot of experimentation this is what I found out:
Our web service up to this point was using the Request / Response classes for input and output. There were required in 1.0, and were a carry over from that. I attempted to create a simple entry point that sent in a string and returned a string. This compiled ok, but:
Although you can use regular types for input and output, if you are using Request / Response types exchanges for other entry points, then you cannot.
Mixed method of request / response and regular types will compile, but it will not successfully import (at least into Visual Studio 2008). What ends up being created seems to be an attempt to create input and output classes for all of the functions to translate them to their complex types, along with the Request / Response types which creates duplicate entries and will not compile.
This then also means that you cannot send in a request object and return a string (which is how I found out that this was not allowed) – this generated an error in the unit test, which started me down this path.
So if you have a request / response web service, all functions must follow that protocol.