WCF returning nil value and actual value in Data Contract - wcf

I have WCF service that is calling another WCF service to get some information from one of our systems and it appears that the values being returned contained some nil values. However, on looking at the XML that was returned, it appeared that the returned values contain two entries for the same DataMamber, one with a nil value and one with the actual value i was expecting eg,
I see something similar to the following in the of the XML returned where the DataMembers have nil values:
<b:AccountNumber i:nil="true" />
<b:Created>0001-01-01T00:00:00</b:Created>
<b:CreatedBy i:nil="true" />
<b:EmailAddress i:nil="true" />
<b:GivenNames i:nil="true" />
and then in the same document but further down, I see the following where the same Data Members have the values I expect:
<b:Id>16996172</b:Id>
<b:Created>2007-07-16T16:32:48.789755</b:Created>
<b:CreatedBy>SYSTEM</b:CreatedBy>
<b:RowStatus>None</b:RowStatus>
<b:AccountNumber>1234567</b:AccountNumber>
<b:EmailAddress>email#test.com.au</b:EmailAddress>
<b:GivenNames>TEST NAME</b:GivenNames>
Not all the DataMembers that are being returned are duplicated like this and it seems that a few values are returned with nil then all of the correct values are returned.
Has anyone seen something like this before or could hazard a guess as to what could be causing it?

It seems that the problem was caused by the WSDL and Data Contracts not matching the web services themselves.
Running svcutil.exe against the web services that were running and not the WSDL files provided fixed the problem.

Related

SoapUI Assertions - either XPath or Contains Assertion would be fine

Sample response below. I want to check the existence of a specific error code (860) in the response below. Technically, to avoid picking the error up accidentally in a reference number, I need to be checking it is in the bit labelled < code >860< /code > (inserted spaces so it would show).
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:activatePortResponse xmlns:ns2="http://transferobjects.abc.abc.org">
<return som="6001365" state="Approved">
<errors>
<error>
<code>860</code>
<description>The Port cannot be activated outside the ready for service dateTime window (grace period taken into account).</description>
<mnemonic>RFS_WINDOW</mnemonic>
</error>
<name>som</name>
</errors>
<success>false</success>
</return>
</ns2:activatePortResponse>
</soap:Body>
</soap:Envelope>
I was trying to build a set of calls with expected error results to check the the error responses are returned as they should. Going through all the usual garbage messages that meant nothing to me, I just kept tweaking.
Turned out I could use a Contains method and just paste in more, rather than just 860 or even < code >860< /code > I just had to paste in a bigger chunk like this:
<error>
<code>860</code>
<description>The Port cannot be activated outside the ready for service dateTime window (grace period taken into account).</description>
<mnemonic>RFS_WINDOW</mnemonic>
</error>
So I have a solution, but if anyone wants to show me how to do it with XPath, in a less hamfisted way, that would be cool.
You could do an XPath Match assertion with the following expression //error/code, which in the above response message would find 860. This way you know that this 860 has been found at a particular place in the XML hierarchy.

XmlPeek empty string causes failure

So in my targets file, I've got a line that looks like this:
<XmlPeek Namespaces="" XmlInputPath="file.xml" Query="/data/#AttributeOne">
<Output TaskParameter="Result" ItemName="my_AttributeOne" />
</XmlPeek>
in "file.xml", I have:
<data AttributeOne="abc" AttributeTwo="def" />
it also reads a few other attributes.
When the attribute has data, everything works fine... but when I leave AttributeOne as an empty string (""), XmlPeek blows chunks with the following error:
The "XmlPeek" task's outputs could not be retrieved from the "Result" parameter. Parameter "includeEscaped" cannot have zero length.
if I remove the attribute ENTIRELY, it works fine (the resulting item is obviously and understandably blank)
The question is... how can I DETERMINE, WITHOUT blowing chunks, the value of a blank attribute... whether by pre-testing for a value, or by correctly handling the blank, or some other means.
CONSTRAINT: the only real requirement is to stick to the built-in tasks (XmlPeek)... I'm aware of XmlRead in the community tasks... for various reasons, I want to use out-of-the-box tasks.
Thanks in advance!
The error happens because an empty string is being used as the Item Identifier. I guess identifiers cannot be the empty string. If you remove the attribute then the result is null and no Item is created so that's why that doesn't throw an error.
Maybe try return the result as a Property instead of an Item.
If you do not need to distinguish between the attribute being omitted versus having an empty value, you can prevent the error by inserting the condition [#AttributeOne!=''] into the query as follows.
<XmlPeek Namespaces="" XmlInputPath="file.xml" Query="/data[#AttributeOne!='']/#AttributeOne">
<Output TaskParameter="Result" ItemName="my_AttributeOne" />
</XmlPeek>

WSO2 ESB route endpoints based on results from DSS

So pretty much I want to call
/sendAllUsersAnEmail
Which will call the DSS and do something along the lines of SELECT user_id FROM users WHERE status = 'PENDING'
Here is the issue. How can I get the ESB to loop through the results (or can I get the DSS to call an API directly?) and make a call to /sendEmail/{user_id} for each user? or is this not possible and do I need to return the results to an outside language and call the esb again for each results.
If I understand what you need it´s something like that:
You have a table inside your system DB, with the user_id from users pending to do something in your system and you need to consult this table, get the list of user_id and for every entry in this list made a call to a restful service passing the user_id
So my idea is:
Use a data service to obtain the user_id list.
Create a proxy service that in seq1 call this data service and in a seq2 get the result.
In seq2 use the iterator mediator and splits the messages into parts and processes them asynchronously like in this sample: https://docs.wso2.com/display/ESB481/Sample+400%3A+Message+Splitting+and+Aggregating+the+Responses
An example:
<iterate expression="//m0:getQuote/m0:request" preservePayload="true"
attachPath="//m0:getQuote"
xmlns:m0="http://services.samples">
<target>
<sequence>
<send>
<endpoint>
<address
uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
</sequence>
</target>
</iterate>
I hope this help you.
Regards.

WCF Data Service REST Client - duplicated entries

We are using the newest WCF dlls (5.6.1) to implement OData Client. We send a request to a service and we are supposed to get multiple, various entries. Unfortunately, something goes wrong and in the response we are getting the correct count of entries, which are incorrectly duplicated (The entry which is the last one is repeated by the count of entries). When the url, which is sent to the service, is executed in browser the entries in response are correct - every entry is different. The same situation is when in linq query I select only some of the columns by new{x.column1, x.column2} - every entry is different.
This is part of the response from browser:
<entry>
<id>...</id>
<title type="text">...</title>
<updated>2014-05-22T08:44:46Z</updated>
<category term="GET_AVG_CONS.Y_AVG_CONS_YEAR" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="Y_AVG_CONS_YEAR_COLLECTION(Customer='1000000167',CompCode='DE0J')" rel="edit" title="Y_AVG_CONS_YEAR"/>
<content type="application/xml">
<m:properties>
<d:BpCat/>
<d:Cusvalsg/>
<d:Salesorg/>
<d:Flag/>
<d:Calmonth>201309</d:Calmonth>
<d:BpCatX/>
<d:CusvalsgX/>
<d:SalesorgX/>
<d:FlagX/>
<d:CalmonthX/>
<d:Customer>1000000167</d:Customer>
<d:ProdHier/>
<d:CompCode>DE0J</d:CompCode>
<d:HierX/>
<d:OrdMeth/>
<d:Nptotcap>2200.000</d:Nptotcap>
<d:Type/>
<d:Code>000</d:Code>
<d:Message/>
</m:properties>
</content>
</entry>
<entry>
<id>...</id>
<title type="text">...</title>
<updated>2014-05-22T08:44:46Z</updated>
<category term="GET_AVG_CONS.Y_AVG_CONS_YEAR" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="Y_AVG_CONS_YEAR_COLLECTION(Customer='1000000167',CompCode='DE0J')" rel="edit" title="Y_AVG_CONS_YEAR"/>
<content type="application/xml">
<m:properties>
<d:BpCat/>
<d:Cusvalsg/>
<d:Salesorg/>
<d:Flag/>
<d:Calmonth>201310</d:Calmonth>
<d:BpCatX/>
<d:CusvalsgX/>
<d:SalesorgX/>
<d:FlagX/>
<d:CalmonthX/>
<d:Customer>1000000167</d:Customer>
<d:ProdHier/>
<d:CompCode>DE0J</d:CompCode>
<d:HierX/>
<d:OrdMeth/>
<d:Nptotcap>220.000</d:Nptotcap>
<d:Type/>
<d:Code>000</d:Code>
<d:Message/>
</m:properties>
</content>
</entry>
This is part of the response from linq query selecting all colums:
And this is the response when I select only some of the columns in linq query:
Does anyone know what might be the problem?
#Zoe
The request which is sent by browser as well as from application, which results in duplicated entries, is the same:
IPaddress:port/something/GET_AVG_CONS/Y_AVG_CONS_COLLECTION()?$filter=Customer eq '1000000167'.
The request from application, which results in correct entries is:
IPaddress:port/something/GET_AVG_CONS/Y_AVG_CONS_YEAR_COLLECTION()?$filter=Customer eq '1000000167'&$select=Calmonth,Nptotcap.
#christiandev
I don't understand your question. I'm using linq query. Before the query is executed, there are no entries in collection. After the execution, they are already duplicated.

Struts 2 property not being read from properties file

After following the struts 2 web pages and numerous examples, my application still will not pick up values from the struts.properties file.
I am trying this in order to give some values a money type format:
<s:property value="getText('struts.money.format',{value})" />
My struts.properties file which is under WEB-INF/classes and therefore visible has the following single line
struts.money.format= {0,number,\u00A4##0.00}
I get the string struts.money.format printed to the screen. If I change the first parameter of the getText call, the new string I put also will get printed instead of a true lookup happening.
If I do <s:property value="value" /> I will get back a proper number. If I drop the second argument on the getText call, I would expect to get back the right hand side of the assignment in the properties file, but i get the same struts.money.format back.
I am using Tomcat 6 with Struts 2.2.1.1. Is there an additional part of the puzzle I am possibly leaving out?
So in my struts.xml file, I put this line
<constant name="struts.custom.i18n.resources" value="struts" />
It needs this to know that I am trying to use a struts.properties file. I had assumed that by default a file named struts.properties was along the chain of places to look for a constant such as this. Only if you named it something else did you need to specify that. Even though it is in WEB-INF/classes which is recommended by the Struts 2 documentation, it just simply was not looking in this file.
EDIT
For what it is worth, I also had to modify my struts text tag like so
<s:property value="getText('struts.money.format',{#java.lang.Double#valueOf(value)})" />
Actually, value should have been a BigDecimal, but it was being treated at the view level here as java.lang.String. The problem is that some of the String objects had exponential formatting (like 1.642E07 or something to that effect) and the struts formatter could not handle the exponential formatting. The valueOf eliminates this exponential fomatting