Can WCF be configured to 'refactor' the XMLSchema-instance namespace on a Serialized message? - wcf

We have noted that WCF DataContractSerializer isn't very efficient when it comes to serializing null values during an SOAP call. For audit purposes, we also record the exact message as sent to disk, so this wastes storage. A typical message with more than one nil element is sent like so:
<MyMessage xmlns="myXmlns">
<field0>1234567</field0>
<field1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
<field2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
<field3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
// etc
</MyMessage>
What would be an immeasurable improvement for bandwidth and disk considerations would be to generate a SOAP body such as:
<MyMessage xmlns="myXmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<field0>1234567</field0>
<field1 xsi:nil="true" />
<field2 xsi:nil="true" />
<field3 xsi:nil="true" />
//etc
</MyMessage>
So my question is, how can I change my WCF client to consolidate the XSI namespace on the root element, to prevent it from being repeated on each nil element?

You can't tweak the serializer, however if you implement a message inspector you can manipulate to your hearts content.
If you want to drop the nulls altogether though, and never see if it's not present you could decorate it
[DataMember(EmitDefaultValue=false)]

Related

Cruise Control .NET Security

I am attempting to implement LDAP authentication, along with the required permissions.
<internalSecurity>
<cache type="inMemoryCache" duration="60" mode="sliding" />
<audit>
<xmlFileAudit location="D:\Logs\CCNet_Audit.xml"/>
</audit>
<auditReader type="xmlFileAuditReader" location="D:\Logs\CCNet_Audit.xml"/>
<users>
<ldapUser name="*username*" domain="*localdomain*"/>
</users>
<permissions>
<rolePermission name="Admin" forceBuild="Allow" sendMessage="Allow" startProject="Allow" changeProject="Allow" viewSecurity="Allow" modifySecurity="Allow" viewProject="Allow" viewConfiguration="Allow" >
<users>
<userName name="*username*"/>
</users>
</rolePermission>
</permissions>
Inside my project I have the following XML:
<project name="TestProject" description="TestProject" queue="Q7">
<security type="defaultProjectSecurity" defaultRight="Deny">
<permissions>
<rolePermission name="Admin" ref="Admin"/>
</permissions>
</security>
My log at (D:\Logs\CCNet_Audit.xml) is saying that I am "Denied"
<event><dateTime>2015-08-17T09:30:41.7973762-04:00</dateTime><user>*username*</user><type>Login</type><outcome>Deny</outcome></event>
and the project is unavailable within CC Tray.
My username is correct and I have the domain correct within the configuration (I just don't want to share it).
One thing I have noticed is that There seems to be a case issue within the username that Cruise Control is getting c-Joe.smith versus the english "normalization" of c-Joe.Smith . . . and yes I have tried it both ways.
Any help?
Try setting defaultRight="Allow" for your admin group.
<rolePermission name="Admin" defaultRight="Allow" forceBuild="Allow" sendMessage="Allow" startProject="Allow" changeProject="Allow" viewSecurity="Allow" modifySecurity="Allow" viewProject="Allow" viewConfiguration="Allow" >
<users>
<userName name="*username*"/>
</users>
</rolePermission>

Batch processing Google Contact Groups with API (php)

I'm trying to do batch processing of Google Contact groups. I have batch processing working for the actual contacts, but groups are not behaving. The XML that I send to Google is:
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom'
xmlns:gContact='http://schemas.google.com/contact/2008'
xmlns:gd='http://schemas.google.com/g/2005'
xmlns:batch='http://schemas.google.com/gdata/batch'>
<entry>
<batch:id>create</batch:id>
<batch:operation type='insert'/>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/contact/2008#group'/>
<title type='text'>Status:Followup 1</title>
<content type='text'>Status:Followup 1</content>
</entry>
</feed>
The response I got back from google was:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:batch="http://schemas.google.com/gdata/batch"
xmlns:gContact="http://schemas.google.com/contact/2008"
xmlns:gd="http://schemas.google.com/g/2005">
<id>https://www.google.com/m8/feeds/contacts/awallace%40ihouseweb.com/full/batch/1430425819721000</id>
<updated>2015-04-30T20:30:19.721Z</updated>
<title type="text">Batch Feed</title>
<entry gd:etag=""SHs-ezVSLit7I2A9XRVTFE8PTwU."">
<batch:id>create</batch:id>
<batch:operation type="insert"/>
<batch:status code="201" reason="Created."/>
<id>http://www.google.com/m8/feeds/contacts/awallace%40ihouseweb.com/base/4b9f4f69095d670d</id>
<updated>2015-04-30T20:30:19.553Z</updated>
<app:edited xmlns:app="http://www.w3.org/2007/app">2015-04-30T20:30:19.553Z</app:edited>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/>
<title/>
<content>Status:Followup 1</content>
<link rel="http://schemas.google.com/contacts/2008/rel#photo" type="image/*"
href="https://www.google.com/m8/feeds/photos/media/awallace%40ihouseweb.com/4b9f4f69095d670d"/>
<link rel="self" type="application/atom+xml" href="https://www.google.com/m8/feeds/contacts/awallace%40ihouseweb.com/full/4b9f4f69095d670d"/>
<link rel="edit" type="application/atom+xml"
href="https://www.google.com/m8/feeds/contacts/awallace%40ihouseweb.com/full/4b9f4f69095d670d"/>
</entry>
</feed>
(note, there were actually 4 groups in my batch, but the results were identical).
The groups in my account were unchanged. I have successfully added and deleted groups one at a time (without the batch syntax/url). The result XML here says explicitly that the group was created (), but the title element is empty in the return. ()
Any ideas?
Thanks,
Andy
I had a similar problem when batch creating groups. My problem was I had no entry for gd:extendedProperty:
eg:
<?xml version="1.0"?>
<feed xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:gContact="http://schemas.google.com/contact/2008" xmlns:batch="http://schemas.google.com/gdata/batch">
<entry>
<batch:id>create</batch:id>
<batch:operation type="insert"/>
<atom:category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#group"/>
<atom:title type="text">Test 1</atom:title>
<gd:extendedProperty name="Test 1">
<info>Test 1</info>
</gd:extendedProperty>
</entry>
...
</feed>
The XML markup you have appears to be for updating an existing group. Have a look at the documentation for more info:
https://developers.google.com/google-apps/contacts/v3/#batch_operations_for_contact_groups

WCF Client adds namespace to XML before parsing

I'm currently implementing a WCF Client app which consumes a Java webservice that uses SOAP as the communication protocol. I generated a proxy from the WSDL provided by the server and when I make calls everything runs through without an error but the received list contains no elements.
I've looked at the incoming XML with Wireshark and WCF tracing/message logging and therefore can be certain that I do receive the intended data. But it seams that the WCF Client somehow manipulates the XML before parsing by inserting an empty namespace which prevents the deserializer from creating the objects from the xml.
Wireshark
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header/>
<SOAP-ENV:Body xmlns:ns="stat">
<ns:mt_getStation>
<ROW>
<Station_ID>96</Station_ID>
<Station>Station Test</Station>
<Timestamp>2014-09-15T14:00:35</Timestamp>
</ROW>
<ROW>
<Station_ID>42</Station_ID>
<Station>Answer Station Test</Station>
<Timestamp>2014-09-15T14:00:35</Timestamp>
</ROW>
</ns:mt_getStation>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
WCF Message log
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header></SOAP-ENV:Header>
<SOAP-ENV:Body xmlns:ns="stat">
<ns:mt_getStation>
<ROW xmlns="">
<Station_ID>96</Station_ID>
<Station>Station Test</Station>
<Timestamp>2014-09-15T14:00:35</Timestamp>
</ROW>
<ROW xmlns="">
<Station_ID>42</Station_ID>
<Station>Answer Station Test</Station>
<Timestamp>2014-09-15T14:00:35</Timestamp>
</ROW>
</ns:mt_getStation>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How can I prevent the WCF client from inserting the empty namespaces?

Tsung Issue with Dyn_Variable

I am very new to ERLANG and TSung, I never worked in this areas, but I am very much keen to know the fundamentals and do distributed load test for my web application. I am in half the way to complete, but I have a big hurdle and not able to moving forward , please read below tsung.xml file and advise me where & what I am missing?
**===> tsung.xml (this file perfectly working without any errors)**
*<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
<tsung loglevel = "debug" dumptraffic="true" version="1.0">
<clients>
<client host="localhost" weight ="1" maxusers="40000" cpu = "1" >
<ip value = '127.000.000.111'/>
</client>
</clients>
<servers>
<server host="127.000.000.112" port="80" type="tcp"></server>
</servers>
<load duration="1" unit="minute">
<arrivalphase phase="1" duration="1" unit="minute">
<users arrivalrate="10" unit="second"></users>
</arrivalphase>
</load>
<sessions>
<session name="mySession" probability="100" type="ts_http">
<transaction name="trx">
<request>
<dyn_variable name="myId" re="<myId>(\.*)\</myId>"/> <-- Trying with RegExp option, not getting the value myId
<!--dyn_variable name="myId" xpath="//response/myId" /--> <-- Trying with xpath option, not getting the value myId
<!--dyn_variable name="myId" jsonpath="response.myId" /--> <-- Trying with jsonpath option, not getting the value myId
<http url='http://127.000.000.112/Create_Rec' method='POST' version='1.1' content_type='text/xml'/>
</request>
<request subst="true">
<http url='http://999.000.000.999/Get_Rec/myId=%%_myId%%' method='GET' version='1.1' content_type='application/xml'/>
</request>
</transaction>
</session>
</sessions>
</tsung>*
When I run this url (it is web service call) "http://_127.000.000.112/Create_Rec" in the web browser, I get the following similar response from Server (in the back ground it creates the record in database and generates new id i.e. myId). When I run above tsung.xml, the first request working perfectly fine as I expected.
===> response (browser response)
<response id="SomeWebService">
<status>
<statusCode>1</statusCode>
<statusMsg>SomeMessage</statusMsg>
<statusTime>2013-06-20 02:52:25</statusTime>
</status>
<myId>298346728934734987</myId>
</response>
What I am looking here, I need to grab the myId from first request and pass into second request myId=%%_myId%%, but it is never working and myId always empty string. I am beyond of dyn_variable since two days, no clue and proper examples/documentation on it. Please suggest me, what I am missing.
You will have to set up the subst="true" in your request for substitution to work. So, your request should change to..
<request subst="true">
If still it doesn't work then I would suggest you to see the tsung.dump file and check the response which you are getting from server

request generation in vb.net soap client

Take the tripservice wsdl from this link In this wsdl, I replaced the from element with the below(added nillable as true and added min length and max length restriction).
<xs:element minOccurs="0" name="from" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="12"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Now in my vb.net client i invoked the service by adding service reference, wsdl saved to a local folder.
Dim objproxy As New Tripservice.TripPriceServiceFacadeClient
Dim gh As New Tripservice.trip
gh.adults = 9
gh.duration = 8
gh.rooms = 8
gh.to = "p"
objproxy.getTripPrice(gh)
It will throw end point not found exception, however i am interested in the request xml that is going. I enabled the trace and found that the below request is generated.
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<getTripPrice xmlns="http://trip.price.service">
<trip xmlns="">
<adults>9</adults>
<duration>8</duration>
<from xsi:nil="true"/>
<rooms>8</rooms>
<to>p</to>
</trip>
</getTripPrice>
</s:Body>
</s:Envelope>
The element from xsi:nil="true" is generated, even though i am not touching the element in my vb.net code to generate the request. The element is optional as per the wsdl(min occurs = 0). How can i send a request without the from element name, even passed in the request?
You can't; it is interesting to find out why you changed it to nillable; in doing that, the way .NET code generation works, you leave it no way to know whether it should marshall the tag or not; typically, an optional string that is null is not marshalled. An optional (minOccurs=0) and nillable wouldn't work since there is no "set" indicator (JAXB has it or use to have it) to keep trace whether the user code set the value, null or not null.