Set namespace prefix on FaultCode c#.net - c#

I am expecting following response for faultCode to be send to client if any fault occurs in FaultException. From custom certificate validator put on BizTalk receive location
<faultcode xmlns:ssek="http://myschemas.testns.org/testns/2006-05-10/">ssek:InvalidCertificate</faultcode>
But when i have written following code.
FaultCode code = new FaultCode("InvalidCertificate", "http://myschemas.testns.org/testns/2006-05-10/");
throw new FaultException("Received Invalid Client Certificate", code);
FaultCode coming as
<faultcode xmlns:a="http://myschemas.testns.org/testns/2006-05-10/">a:InvalidCertificate</faultcode>
I want to modify prefix "a" with "ssek".
Please can somebody help me with this.
Regards
Kundan

Related to this MSDN article, this the default behavior when the FaultCode is serialized.
to override this generation, you can create a custom MessageFormatter. there is a good article explaining how to do it with an attribute on contract operations.
hope that helpe you.

Related

Soap Request FaultException.Detail is always empty

I am using a third party service & hence has no access to change anything from service side. I WSDL which I added as connect service.
The problem is that I have enabled the raw request & I can see error details in trace or debug log. But When I try to fetch details using following code it always return empty Detail Object.
try {
// my code to call service
}
catch (System.ServiceModel.FaultException<Error[]> errors) {
var err = Newtonsoft.Json.JsonConvert.SerializeObject(errors.Detail)
Console.WriteLine(err);
}
Edit: looks to be a duplicate of
FaultException.Detail coming back empty
The problem was the visual studio didn't quite map out the ErrorDetail objects right. The ErrorDetail node is called "ErrorDetail", but the type generated for it is "ErrorDetailType." I edited the reference.cs class generated for each service I was using and added a TypeName:

Can anyone tell me what SoapDocumentMethodAttribute does?

Can anybody explain to me what the following code does? Specifically, the attribute on the GetStatus method. I know it has something to do with SOAP requests, but I tried googling "SoapDocumentMethodAttribute" and didn't find much that explains things. Can anybody dumb it down for me please?
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://dummyurl.com/", RequestNamespace = "http://dummyurl.com/", ResponseNamespace = "http://dummyurl.com/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string GetStatus(string Username, string Password, string EndSystemUser) {
object[] results = this.Invoke("GetStatus", new object[] {
Username,
Password,
EndSystemUser});
return ((string)(results[0]));
}
Soap services expose WSDL to the consumers which contain information about how SOAP messages would be written.
This WSDL can be written either in RPC style or in Document Style.
Document style is perfered over RPC style as it means less coupling and provides better way to validate the message.
This attribute instructs WSDL generator to use Document Style.
From the MSDN Documentation:
Web Services Description Language (WSDL) defines two styles for how an
XML Web service method, which it calls an operation, can be formatted
in a SOAP message: RPC and Document. Document refers to formatting the
XML Web service method according to an XSD schema. The Document style
refers to formatting the Body element as a series of one or more
message parts following the Body element.
Refer this link for examples of RPC / Document style.

Error when creating JWT Token

As I am on my way to switch from using the legacy header authentication method to the JWT Token method, I have used the following example found here.
However, I get the following error :
Error calling Login: {
"errorCode": "PARTNER_AUTHENTICATION_FAILED",
"message": "The specified Integrator Key was not found or is disabled. An Integrator key was not specified."
}
Below is my C# code.
string oauthBasePath = "account-d.docusign.com";
string privateKeyFilename = "./private.pem";
int expiresInHours = 1;
ApiClient apiClient = new ApiClient(docuSignUrl);
apiClient.ConfigureJwtAuthorizationFlow(
"IntegratorKey",
"USER ID GUID",
oauthBasePath,
privateKeyFilename,
expiresInHours);
AuthenticationApi authApi = new AuthenticationApi(apiClient.Configuration);
return authApi.Login();
I have found this thread that shows the similar error but it doesn't seem resolved
Update 05/07/2018: I have validated the domain used in my account but I still get the same error message
Update 05/11/2018: When I use my code but that I replace the IntegratorKey, UserID and private key used in the DocuSign Unit Tests here, my code now works !? Hence, I can only conclude that the issue doesn't come from my code but maybe a configuration issue on the DocuSign side ? do I need to configure my Integrator Key a specific way ?
After more investigation, the reason with such an error is that I was not generating the Authorization Code Grant prior to executing my code.
Based on the information found here, I had to perform the following HTTPRequest example :
GET /oauth/auth?
response_type=token
&scope=signature
&client_id=YOUR_INTERGRATOR_KEY
&state=a39fh23hnf23
&redirect_uri=http://www.example.com/callback
Once it is approved, then I can run my code successfully.
In the end, the initial error message is really misleading (I might argue it could be considered a bug ?).

C# Loggly.info Not working

Hello could you help me with this problem:
Loggly I'm using C #, and I want to make a simple log, I found something similar to this:
var logger = new Logger("KEY", "logs-01.loggly.com");
logger.Log("Hello World¡¡¡");
but does not work, the relevant documentation is here:
Link Loggly Documentation
Help me please, thanks =)
Code that you provided works fine. Make sure that you use correct inputKey.
It should be just Customer Token or token plus some extra tags. For example:
var logger = new Logger("********-****-****-****-************/tag/tag1,tag2,tag3", "your-application-name");
logger.LogWarning("Hello World !!!");
You can use a packet capture tool like Fiddler to make sure events are being sent to Loggly successfully. You should see outbound events to logs-01.loggly.com on port 80.
Try enable ThrowExceptions
#if DEBUG
LogglyConfig.Instance.ThrowExceptions = true;
#endif
This will cause Loggly to throw an exception instead of silently fail. You may want logging to silently fail in production rather than break your app.
In my case the exception message wasn't very helpful, but it did spot that I was adding a tag with a null value. The tag was optional, but if you try to create one with a value of null, the log will not get transmitted.

.NET Web Service - How to return an error?

I've been working on some web services lately in c# asp.net (3.5).
My method is like so and returns a User object consisting of some basic user-related fields (name, age, i etc)..
[WebMethod, SoapHeader("AuthHeader")]
public user[] Employees(int count)
{
user[] myUsers = new user[count];
<logic here inc. checking if user is authorised>...
return myUsers;
}
If authorisation fails for the client consuming the web service id like to return an error within the web service, correctly formatted.
Whats the best practice way to achieve this? I guess simply pushing a Response.StatusCode or a Null return isnt good practice?
My current payload XML when auth'd looks like..
<ArrayOfUser>
<user>
<empid>57344</empid>
<firstname>Dave</firstname>
<surname>Johnson</surname>
</user>
<user>
<empid>17324</empid>
<firstname>Mike</firstname>
<surname>Doe</surname>
</user>
</ArrayOfUser>
If an error occurs should I be returning something like...?
<soap:error>
<errorcode>12345</errorcode>
<errorstring>Invalid username/password</errorstring>
</soap:error>
Or is there a better best practice way?
Second issue is, how would I structure my method so I could return such a XML structure? At present my "Employees" method is of type "User[]" so must return an array of type "User", but if theres been an error I want to return a different type to simulate an XML structure as above or even a simple string stating an error has occured.
How would I achieve this?
Any help would be great! Cheers!
Just have your method throw an exception - the .Net framework will convert that into a SOAP error message.
If you want more control over the SOAP error message returned then throw a SoapException
For error handling : You need a good exception handling framework to support your application. If you are using enterpriselibrary exception handling use the below line of code.
enter code here
catch (Exception ex)
{
ExceptionPolicy.HandleException(ex, "Client Service Policy");
}
It again depends on what message you want to show it to the user. You can log the actual error message and throw customized message to the end user, you can do with the exception handling framework.
You can get more details on implementing exception handling framework.
http://www.devx.com/dotnet/Article/31463/1954
For returning xml : you can create the elements as shown below. Finally you can convert the xelement to string and you can use the string in your caller method (the string is nothing but XML)
enter code here
string[] directoriesList = Directory.GetDirectories(System.IO.Path.GetFullPat ("\\mynetworkpath")));
XElement foldersXML = new XElement("Folders");
foldersXML.Add(from directory in valueList select new XElement("Folders", new XAttribute("name", directory.Split('\\')[directory.Split('\\').Length - 1])));

Categories

Resources