Not sure how to add another property to WCF? - wcf

I have inherited a web project that uses WCF in a separate project of my solution to get the data. I'm not familiar with WCF but I was asked to see if I could send another parameter. A developer that is responsible for the actual Web Service will make the adjustment for the extra parameter on his side.
I did a search in the solution for the property called crewMemberConMonthField so I could just copy and paste a new one called crewMemberConMonthField2. I found it in the References.cs and in a FH_FTPService.xsd file.
In the .xsd file I copy and pasted the XML and just changed the name. I then went to the refernces.cs file and added another parameter with the new name (crewMemberConMonthField2). Since I'm using VS 2015 it gives me the option to refactor the name but when I do I get a warning message that basically says "the file could not be refactored. The current object is auto-generated by the Wcf Client Generator and cannot be renamed".
I've been searching for information about this but everything I'm finding is try to walk me through created a WCF. When I look through those examples I'm not seeing anything about a Wcf Client Generator.
I was looking to see if anyone could maybe point me in the right direction.
Here is some of what I have in the reference.cs
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18408")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://sitename.com/FH_FTPService/")]
public partial class StartRequestType : object, System.ComponentModel.INotifyPropertyChanged {
private StartRequestTypePartition partitionField;
private string crewMemberConMonthField;
private string crewMemberConMonthField2;
private string sequenceConMonth1Field;
private string sequenceConMonth2Field;
and this is in my .xsd file
<schema xmlns:tns="http://sitename.com/FH_FTPService/" elementFormDefault="qualified" targetNamespace="http://sitename.com/FH_FTPService/" xmlns="http://www.w3.org/2001/XMLSchema">
<complexType name="StartRequestType">
<sequence>
<element name="CrewMemberConMonth">
<simpleType>
<restriction base="string">
<length value="7" />
<pattern value="^(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)\d{4}$" />
</restriction>
</simpleType>
</element>
<element name="CrewMemberConMonth2">
<simpleType>
<restriction base="string">
<length value="7" />
<pattern value="^(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)\d{4}$" />
</restriction>
</simpleType>
</element>

Related

Add Friend Classes to Exclusion List of Obfuscation

I'm using Dotfuscator CE with Visual Studio 2015 Update 3 to obfuscate my .Net assemblies.
We know that Public types and members are not be obfuscated by default.
I'm curious to know how can we add Friend Classes in Exclusion list so that those should not be obfuscated?
Here is the config file file I'm using to obfuscate my DLL.
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE dotfuscator SYSTEM "http://www.preemptive.com/dotfuscator/dtd/dotfuscator_v2.3.dtd">
<dotfuscator version="2.3">
<propertylist>
<property name="SourceDirectory" value="This Path Will Be Replaced By Visual Studio" />
<property name="SourceFile" value="This Filename Will Be Replaced By Visual Studio" />
</propertylist>
<global>
<option>quiet</option>
</global>
<input>
<asmlist>
<inputassembly refid="e4ca1ab5-26cb-4ab7-9621-87063f75a38f">
<option>honoroas</option>
<option>stripoa</option>
<option>library</option>
<option>transformxaml</option>
<file dir="${SourceDirectory}" name="${SourceFile}" />
</inputassembly>
</asmlist>
</input>
<output>
<file dir="${SourceDirectory}" />
</output>
<renaming>
<option>xmlserialization</option>
<mapping>
<mapoutput overwrite="true">
<file dir="${SourceDirectory}\Dotfuscated" name="Map.xml" />
</mapoutput>
</mapping>
<referencerulelist>
<referencerule rulekey="{6655B10A-FD58-462d-8D4F-5B1316DFF0FF}" />
<referencerule rulekey="{7D9C8B02-2383-420f-8740-A9760394C2C1}" />
<referencerule rulekey="{229FD6F8-5BCC-427b-8F72-A7A413ECDF1A}" />
<referencerule rulekey="{2B7E7C8C-A39A-4db8-9DFC-6AFD38509061}" />
<referencerule rulekey="{494EA3BA-B947-44B5-BEE8-A11CC85AAF9B}" />
<referencerule rulekey="{89769974-93E9-4e71-8D92-BE70E855ACFC}" />
<referencerule rulekey="{4D81E604-A545-4631-8B6D-C3735F793F80}" />
</referencerulelist>
</renaming>
<sos mergeruntime="true">
<option>version:v4</option>
<option>sendanalytics</option>
<option>dontsendtamper</option>
</sos>
<smartobfuscation>
<smartobfuscationreport verbosity="all" overwrite="false" />
</smartobfuscation>
</dotfuscator>
Actually I've a Model class with Friend access specifier. I post its object via PostAsJsonAsync method e.g.
Dim result As HttpResponseMessage = client.PostAsJsonAsync(APIEndPoints.LOGIN, _LoginModel).Result
Here is the Friend Class:
Friend Class LoginModel
Public AccessKey As String
Public Password As String
End Class
API method that receives the request and model:
[HttpPost]
[Route("authenticate")]
public async Task<JsonResult> Authenticate([FromBody] LoginViewModel lvm)
// Here lvm.Accesskey is null
When API receives the request and LoginModel too, its fields are null. If I make my LoginModel public then it works.
Note: this only happens when I obfuscate my DLL, otherwise the implementation works with Friend class too.
Also note: Friend classes are common in VB.Net. They works like public classes when accessed within an assembly but they are private outside the assembly.
Based on your clarification, it sounds like you want to exclude not only the names of Friend types, but also the names of Public fields within those types. I had interpreted your original question as wanting to exclude anything marked Friend, no matter the context.
An important point here is that, in terms of Dotfuscator's rules, excluding a type does not automatically exclude its members.
Here's an exclusion rule set that excludes top-level Friend types and Public and Friend fields of those types:
<excludelist>
<type name=".*" regex="true" speclist="+notpublic">
<comment>Exclude top-level types that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "private" in IL).</comment>
<field name=".*" speclist="+public" regex="true">
<comment>Exclude public fields of types the parent rule matches</comment>
</field>
</type>
</excludelist>
You can also just exclude types and members you know will cause trouble when renamed, rather than excluding a large number of names using rules based on accessibility. Here's an example, assuming LoginModel is defined in assembly YourAssembly and namespace YourNamespace.Here:
<excludelist>
<type name="YourAssembly.YourNamespace.Here.LoginModel">
<field name="AccessKey" signature="string" />
<field name="Password" signature="string" />
</type>
</excludelist>
(I noticed you're using this same configuration for multiple input assemblies, but this rule is still safe because if the input assembly doesn't contain the specified type, then the rule will be ignored.)
For reference, the Professional Edition documentation on Exclusion Rules (and sub-topics of that page) might be useful - Community Edition and Professional Edition share the same configuration file format, for features that are supported by both editions.
Disclosure: I work on the Dotfuscator team for PreEmptive Solutions.
If you are trying to exclude your input assembly's Friend types and members because your assembly has a Friend Assembly, then be aware that Dotfuscator will automatically exclude such code elements from renaming (the only kind of obfuscation provided by Dotfuscator CE) and will issue the following warning:
WARNING: NameOfYourInputAsssembly has non-input Friend Assemblies and is in Library Mode; internal members will not be renamed or pruned. Consider adding Friend Assemblies as input for increased obfuscation.
(The term "internal" here is the C# equivalent of VB's "Friend" keyword).
As the warning suggests, you can instead include the Friend Assembly as another Input to Dotfuscator.
If you do so, Dotfuscator can then rename the Friend types and members, and update the Friend Assembly to refer to those types and members by the new names.
If you still would like to exclude Friend types and members, you can do so with the following renaming exclusion rule set, added as a child of the <renaming> tag in the config file:
<excludelist>
<type name=".*" regex="true" speclist="+notpublic">
<comment>Exclude types that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "private" in IL).</comment>
</type>
<type name=".*" regex="true" speclist="+nestedassembly">
<comment>Exclude nested types that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "private" in IL).</comment>
</type>
<type name=".*" regex="true" excludetype="false">
<comment>Select, but do not exclude, all types.</comment>
<method name=".*" speclist="+assembly" regex="true">
<comment>Exclude methods that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "assembly" in IL).</comment>
</method>
<field name=".*" speclist="+assembly" regex="true">
<comment>Exclude fields that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "assembly" in IL).</comment>
</field>
<propertymember name=".*" speclist="+assembly" regex="true">
<comment>Exclude properties that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "assembly" in IL).</comment>
</propertymember>
<eventmember name=".*" speclist="+assembly" regex="true">
<comment>Exclude events that are only accessible to the assembly ("Friend" in VB, "internal" in C#, or "assembly" in IL).</comment>
</eventmember>
</type>
</excludelist>
Edit: I had missed nested types in the previous revision of this answer.
Disclosure: I work on the Dotfuscator team for PreEmptive Solutions.

How to consume WCF service from BizTalk 2010

I have a web service that I need to consume from BizTalk orchestration.
I've defined message schemas which I use in BizTalk, they look like
<?xml version="1.0" encoding="utf-16"?>
<xs:schema
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns="http://www.myapp.com/schemas/IntegrationApplication-instance"
xmlns:b="http://schemas.microsoft.com/BizTalk/2003"
xmlns:ns0="https://DTIB.PropertySchema"
elementFormDefault="qualified"
targetNamespace="http://www.myapp.com/schemas/IntegrationApplication-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation=".\CommonTypes.xsd" />
<xs:element name="ProviderRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="Header" type="HeaderType" />
<xs:element name="Parameters" type="ParametersType" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
In WCF service I have methods defined like
public ProviderResponse Provide(ProviderRequest providerRequest) {...}
where ProviderRequest is defined like
[DataContract(Namespace = "http://www.myapp.com/schemas/IntegrationApplication-instance")]
public class ProviderRequest
{
[DataMember]
public Header Header { get; set; }
[DataMember]
public Parameter[] Parameters { get; set; }
}
When I create send port and try to send a ProviderRequest message it fails with different errors.
What's the best method to consume a WCF service which uses the same schemas as defined in BizTalk project?
Your best bet is to run an instance of your service and then "Add Generated Items" -> "Consume WCF Service" from within Visual Studio.
This will generate your service message XSDs and port types and is a low-friction way of doing what you are trying to do.
Quite interesting question, a scenario that might happen to others.
Here are some suggestions.
Most common case: You need to consume a service and want to use those messages
- Use hugh's suggestion "Add generated item..."
Less common case: You have already created a schema that a service also uses (the same)
- Use hugh's suggestion "Add generated item..."
- Remove the schema that is a duplicate, either your own or from the created
Not so common case: You want to consume two services that uses the same schema
- Use hugh's suggestion "Add generated item..."
- Remove the schema that is a duplicate from one of the generated
Have never happened to me case: You have already created a schema that a service also uses (NOT the same, but same root name and name space)
- There is nothing to do, this will not work (out of the box)

Problem with struts 2 and json plugin

I'm using the json plugin that comes with struts 2 (json-lib-2.1.jar) and trying to follow the website to set it up.
Here's my struts.xml
<struts>
<package name="example" extends="json-default">
<action name="AjaxRetrieveUser" class="actions.view.RetrieveUser">
<result type="json"/>
</action>
</package>
</struts>
but I get this warning:
SEVERE: Unable to find parent packages json-default
Is there something else I'm supposed to do?
Edit:
I added this method to my RetrieveUser:
public Map<String,Object> getJsonModel()
{
return jsonModel;
}
And my struts.xml looks like this:
<struts>
<package name="example" extends="json-default">
<action name="AjaxRetrieveUser" class="actions.view.RetrieveUser">
<result type="json"/>
<param name="root">jsonModel</param>
</action>
</package>
</struts>
However, I don't think the response is going from the RetrieveUser class to the javascript. I'm using firebug and no request gets sent.
I believe that net.sf.json-lib is just a toolset you can use in your Java to build up JSON-ready objects, suitable to be returned by actions such as you describe.
Probably, you need to include struts-json-plugin - make sure its version matches your struts version.
I notice also that as written, your action will attempt to return RetrieveUser, serialized. Most implementations I've done/seen specify the root object to be returned, by adding
<param name="root">jsonUser</param>
Under the tag, and define this method in RetrieveUser
public Map<String, Object> getJsonUser()
[This is mentioned in the Sruts2 doc]. Hope that helps.
[edit] I use Map - you could also use the object structures provided by json-lib instead.
Re: Your edit. Probably need to see your calling javascript. And probably I will suggest that you make sure you have both a success and an error handler. Can you debug/log to show that the method is being called in java ? Do your logs show anything ? This is usually some sort of error....

wcf : string element nillable="false"

I have a client that is mandating that my required string elements have nillable="false", currently all strings in the wsdl come out will nillable="true", IE:
<xs:element name="username" nillable="true" type="xs:string" />
How can i change the nillable="false" ?!? I will take any suggestions on how to do this? Am I the first person that has run into this?
How is this element defined in your data contract?
If it's not already done, try adding a IsRequired=true clause to the data member attribute:
[DataContract]
class YourDataStructure
{
......
[DataMember(IsRequired=True)]
string username;
.....
}
Other than that, I'm not aware of any way to influence the XSD being rendered from your WCF data contract, short of writing your own WsdlExporter extension (which is totally possible - just seems a bit overkill here).

asmx wsdl string length

I have a VB class in an .asmx file in Visual Studio 2008:
public class foo
public bla as String
end class
It generates the wsdl value:
<s:complexType name="foo">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="bla" type="s:string" />
</s:sequence>
</s:complexType>
But what I want the wsdl to generate is:
<xs:element name="bla" type="xs:string"
sql:datatype="varchar(25)" minOccurs="1" maxOccurs="1">
</xs:element>
Is there a way to do this?
Or can I edit the generated WSDL?
You can use The System.Xml.Serialization.XmlElementAttribute to mark the property IE:
<XmlElement(DataType := "varchar(25)")>
(my vb is a little rusty if this isn't correct
syntax)
You can save off the WSDL and edit it, however, if you change the WSDL, a proxy generated from it may not be able to communicate with your service.
Edit: If you have the target schema, I would suggest that you use xsd.exe or wsdl.exe to generate the classes you need to serialize to valid documents according to that schema.