WCF Data Services access issues - 403 forbidden? - c#

I have Silverlight 4.0 client calling WCF data service, in the service I have write allow to all (I know that is not very wise, but I want to test it first):
public static void InitializeService(DataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
config.UseVerboseErrors = true;
}
when I call the service from the client using BeginSaveChanges like this:
MyServiceEntity.BeginSaveChanges(SaveChangesOptions.Batch, OnChangesSaved, MyServiceEntity);
I receive forbidden error:
--batchresponse_a7bc1f95-8f8d-4e3b-9e24-108743499c3a
Content-Type: multipart/mixed; boundary=changesetresponse_04a92dd2-1fe4-4da5-8d2e-e020fe354f8f
--changesetresponse_04a92dd2-1fe4-4da5-8d2e-e020fe354f8f
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 403 Forbidden
Content-ID: 1
DataServiceVersion: 1.0;
Content-Type: application/xml
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code></code>
<message xml:lang="en-US">Forbidden</message>
</error>
--changesetresponse_04a92dd2-1fe4-4da5-8d2e-e020fe354f8f--
--batchresponse_a7bc1f95-8f8d-4e3b-9e24-108743499c3a--
And Batch operation response code is 202, whatever this is supposed to mean.
Any help is appreciated.

I know its seems very obvious but, did you publish your service to production after you changed the right to allow write?
just make sure you are pointing to the correct service url.
regards.

Related

100K sized POST requests don't get to webAPI?

I'm using Fiddler (or post manager) to invoke requests to my WebApi. ( it's hosted as an ASP.net application in IIS)
This is the service :
[HttpPost]
[ActionName("uploadRessources")]
[AllowAnonymous]
public HttpResponseMessage uploadRessources(ResourcesJson json)
{
...
return Request.CreateResponse(HttpStatusCode.OK, result);
}
For short length body( 3 rows of data) length post data requests like :
POST http://something.com/api/services/uploadRessources HTTP/1.1
Cache-Control: no-cache
Connection: keep-alive
Pragma: no-cache
Accept: application/json
Accept-Encoding: gzip
Accept-Language: he-IL
User-Agent: Mozilla/5.0
Content-Length: 451
Content-Type: application/json
Host: es.com
{ "l":
[{"MasterEntity":2,"screen":"ConfirmHealthDetailsPage","Lbl":"ApproveTheFollowingDetails","enus":"Approve the Following Details:","device":"mobile","description":"NULL"},
{"MasterEntity":2,"screen":"ConfirmHealthDetailsPage","Lbl":"PersonalDetails","enus":"Personal Details","device":"mobile","description":"NULL"},
{"MasterEntity":2,"screen":"FingerPrintResources","Lbl":"CANCEL","enus":"CANCEL","device":"mobile","description":"NULL"}]
}
I DO get a successful response :
HTTP/1.1 200 OK
But for a long body length request ( 101K ) -
It is stuck (it even doesn't hit the breakpoint in my code , while in short request - it does )and I never see a response :
BTW - If later I do run again the short body length request( while still waiting for the previous large requests) - I do get 200 ( for the short length request).
In web.config I did set :
<httpRuntime enableVersionHeader="false" executionTimeout="100000000" maxRequestLength="999999999" />
In IIS : No requests filters
In Event Viewer - I don't see any exceptions or warnings
IIS version : 6.1 ( windows 7) - but it also happens at our server.
Question
Why doesn't my 101k length request - get to my webapi ?
Edit
I've found that it happens for >65k requests. Still don't know what is the problem
It's seems to be an issue with your serializer, tries to put a breakpoint there and see if hits it. If you are not using a custom serializer, creates one temporally just to see what's happen with your request.
It was stuck on request.Content.ReadAsStringAsync().Result ( and never released). Strange but setting it to async , solved the problem. I still don't know why. In General this is the solution - the left pane was the problematic one while the right pane is the working one. ( I must say that the left pane used to work , but after upgrading to 4.6.2 - it started doing problems) - Again - I don't know why

WCF Client cant read "mutlipart/reoated"

I have a simpel WCF-Client.
Binding
var binding = new WSHttpBinding(SecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
So now my Problem. The server respond with somthing like this:
--MIMEBoundary_4c0931c2662c48df1de58a689b82ce1eb3373535d903393a
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-ID: <0.5c0931c2662c48df1de58a689b82ce1eb3373535d903393a#apache.org>
<?xml version="1.0" encoding="UTF-8"?>
<--rest of the response xml-->
--MIMEBoundary_4c0931c2662c48df1de58a689b82ce1eb3373535d903393a--
It looks like the normal respond is simply packed in the MIMEBoundary. I try to switch to MTOM. But i got this Error:
Error creating a reader for the MTOM message.
MTOM messages must have type 'application/xop+xml'
What could i do?

How to get data or retrieve data from Microsoft Dynamics CRM 2015 through SOAPui

I know it may be duplicate question, but in 2015 release I am facing some issue while getting data.
I have read all blogs related to this subject, but could not make it.
I have followed below steps to get data.
Loaded project in SOAPui from http://{server}/{OrgName}/XRMServices/2011/Organization.svc
Edited endpoint, Added /web after Organisation.svc
Added Authentication. (username,password,domain)
Added content-type, SOAPAction, Accept
Still I am getting Bad-Request error.
please help. If possible please give some Request sample.
Thanks.
Here's how to setup requests, make sure you're setup correctly:
Create a SOAP project pointing to http://<organization url>/XrmServices/2011/Organization.svc?wsdl (you'll have to authenticate)
Create a new request for w/e you need to do
In the request, set Authentication to NTLM (provide credentials)
In the request, you'll need three Headers like this (double-check them if you already have them there):
4.1. SOAPAction - copy/paste it from the request interface properties
4.2 Accept - application/xml, text/xml, */*
4.3 Content-Type - text/xml; charset=utf-8
Provide a well-formed request and go
For example, this is what a RetrieveEntityRequest looks like (this in particular will return the metadata of the account entity):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header><a:SdkClientVersion xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">6.0</a:SdkClientVersion></soapenv:Header>
<soapenv:Body>
<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<request i:type="a:RetrieveEntityRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
<a:Parameters xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<a:KeyValuePairOfstringanyType>
<b:key>EntityFilters</b:key>
<b:value i:type="c:EntityFilters" xmlns:c="http://schemas.microsoft.com/xrm/2011/Metadata">Attributes</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>MetadataId</b:key>
<b:value i:type="ser:guid" xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/">00000000-0000-0000-0000-000000000000</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>RetrieveAsIfPublished</b:key>
<b:value i:type="c:boolean" xmlns:c="http://www.w3.org/2001/XMLSchema">true</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>LogicalName</b:key>
<b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">account</b:value>
</a:KeyValuePairOfstringanyType>
</a:Parameters>
<a:RequestId i:nil="true" />
<a:RequestName>RetrieveEntity</a:RequestName>
</request>
</Execute>
</soapenv:Body>
</soapenv:Envelope>

HttpActionContext.Request.Headers.Authorization is null

I am using asp.net mvc 4 rest and write my own basec authentification logic.
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
if (actionContext.Request.Headers.Authorization == null)
{
actionContext.Response = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized);
}
else
{
//do staff here
}
}
It works on local iis. But it does not work on producation station. I always get null. I set basic authentification enabled on IIS. I am testing with Fiddler and my request looks like that:
User-Agent: darwin/1.0 CFNetwork/548.1.4 Darwin/11.0.0
Authorization: Basic cmFkaWt2b3N0b2tAZ21haWwuY65tJjE6QkFBREVEcHlQYmtjQkFOcXh4UmFrdG1JMUJ2bjBPYXVQVk9NcnFZMEg4V3BhakljSlk2WkJMTWtra1FIWHFrcEZmdEkyNmFEZEppYWlKVVZJOTZpUGJuMzRMc1luemJHM2FPV3paQk5DTG1Xak9FZGU3YTdGWVhVem1QeTlEWkM4cW02YWZoWkJGWkIzbGFXMTNaQjlKdQ==
Content-Length: 10128
Accept: application/json
Content-Type: application/json
Connection: keep-alive
Host: 192.168.7.4
Does anybody know why it happens?
First of all, implement OnAuthorization() instead of OnActionExecuting(). OnAuthorization() is executed prior to OnActionExecuting(). It's important to check for authorization even before the user reaches OnActionExecuting() codes.
But your answer: the most possible situation is that the <authentication> is set to "None" in production web.config file. Change it as follows and you'll be all set:
<authentication mode="Forms"/>

Getting MIME type from Web Service Response header

I invoke a web service provided by an external partner company. The web service returns files (.pdf, .dox, .png, ...) as a byte array.
If I would need to get the Header information (in detail I am interested in the content-type data) from the code, how can I get this information?
On our side, we are using VS 2010 and C# as language.
Here the code:
var client = new PublicService();
wsRequest request = new wsRequest();
var docInfo = new documentInfo();
docInfo.documentId = HSdocumentID;
docInfo.position = 1;
request.documentInfos = { docInfo };
byte[] doc = client.deliver(deliverRequest); //returns the file as byte array
The RESPONSE header would look like:
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:deliverResponse xmlns:ns2="http://www.dalle.com/webservices/record/2012a">
<return>
<Include xmlns="http://www.w3.org/2004/08/xop/include"
href="cid:d3a#example.jaxws.sun.com"/>
</return></ns2:deliverResponse></S:Body></S:Envelope>
Content-Id: <d3a#example.jaxws.sun.com>
Content-Transfer-Encoding: binary
Content-Type: application/pdf <-- THIS IS THE INFO I NEED TO GET
Check out if there are SOAP headers on the Web Method call that answer your question
On the web method I do not have any properties/attributes that refer to the header. Is there a general way to get the Response header or is the web service that should provide features to get it?
(I provided an answer, rather than a comment, due to the code to be copied)

Categories