KSOAP2 complex request property not being seen - soap

I'm having a problem sending a complex SOAP request to a third-party company server (server can have no changes) from an android device. I'm using KSOAP2 library and one of the properties is missing (server is giving an error which occurs when klausimai is null. Also the same namespace in my request is repeated multiple times when KSOAP2 generates the XML, since I pass a lot of PropertyInfo. My question is, why could the server see other properties (it would also give an error about the null ones) But doesn't see klausimai ?
Sample request XML for WS given by server company
?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<teiktiTemineAtaskaita xmlns="http://tempuri.org/">
<userName>apps</userName>
<password>mob2015*</password>
<uzduotiesNr>24287</uzduotiesNr>
<inspektavimas xmlns:a="http://schemas.datacontract.org/2004/07/DssisMP" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:apsilankymuObjekteSkaicius i:nil="true" />
<a:atstovai i:nil="true" />
<a:darbdavioBuveinesAdresas i:nil="true" />
<a:darbdavioGimimoData i:nil="true" />
<a:darbdavioKodas>110871120</a:darbdavioKodas>
<a:darbdavioLytis i:nil="true" />
<a:darbdavioPagrindineEkonomineVeikla i:nil="true" />
<a:darbdavioPavadinimas i:nil="true" />
<a:darbdavioPavarde i:nil="true" />
<a:darbdavioTipas i:nil="true" />
<a:darbdavioVardas i:nil="true" />
<a:inspektavimoNr>11112245</a:inspektavimoNr>
<a:inspektavimoPradzia>2015-07-23T00:00:00+03:00</a:inspektavimoPradzia>
<a:inspektavimoTiksloKodas>111</a:inspektavimoTiksloKodas>
<a:institucijos i:nil="true" />
<a:savivaldybesKodas i:nil="true" />
<a:temineAtaskaita>
<a:klausimai>
<a:TAKlausimas>
<a:atsakymas>2</a:atsakymas>
<a:eilNr>1.</a:eilNr>
<a:klausimas i:nil="true" />
<a:kodas>1000</a:kodas>
<a:komentaras i:nil="true" />
</a:TAKlausimas>
<a:TAKlausimas>
<a:atsakymas>1</a:atsakymas>
<a:eilNr>1.1.</a:eilNr>
<a:klausimas i:nil="true" />
<a:kodas>1001</a:kodas>
<a:komentaras i:nil="true" />
</a:TAKlausimas>
<a:TAKlausimas>
<a:atsakymas>3</a:atsakymas>
<a:eilNr>2.</a:eilNr>
<a:klausimas i:nil="true" />
<a:kodas>1002</a:kodas>
<a:komentaras i:nil="true" />
</a:TAKlausimas>
</a:klausimai>
<a:nr>BIOCIDŲ PRIEŽIŪRA-0050-0007</a:nr>
<a:rekomendacijos i:nil="true" />
<a:surasymoData>2015-07-23T00:00:00+03:00</a:surasymoData>
<a:tipas>9</a:tipas>
</a:temineAtaskaita>
<a:tikrintaEkonomineVeikla i:nil="true" />
<a:tikrintaNakti i:nil="true" />
<a:tikrintasObjektas i:nil="true" />
<a:tikrintoObjektoAdresas i:nil="true" />
<a:tikrintoObjektoPavadinimas i:nil="true" />
<a:vadovoAsmensKodas i:nil="true" />
<a:vadovoGimimoData i:nil="true" />
<a:vadovoLytis i:nil="true" />
<a:vadovoPareigos i:nil="true" />
<a:vadovoPavarde i:nil="true" />
<a:vadovoVardas i:nil="true" />
</inspektavimas>
</teiktiTemineAtaskaita>
</s:Body>
</s:Envelope>
My HTTPTransport request dump XML generated by KSOAP2
<?xml version="1.0" encoding="UTF-8"?>
<v:Envelope xmlns:v="http://schemas.xmlsoap.org/soap/envelope/" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<v:Header />
<v:Body>
<teiktiTemineAtaskaita xmlns="http://tempuri.org/">
<userName>apps</userName>
<password>mob2015*</password>
<uzduotiesNr>212855</uzduotiesNr>
<n0:inspektavimas xmlns:n0="http://tempuri.org/">
<inspektavimoNr i:null="true" />
<n1:inspektavimoPradzia xmlns:n1="http://schemas.datacontract.org/2004/07/DssisMP" i:type="d:dateTime">2015-07-26T21:00:00.000Z</n1:inspektavimoPradzia>
<inspektavimoTiksloKodas>1101</inspektavimoTiksloKodas>
<darbdavioKodas>120163917</darbdavioKodas>
<darbdavioPavadinimas>Statybos ir remonto uždaroji akcinė bendrovė "RISTATYBA"</darbdavioPavadinimas>
<darbdavioTipas>1</darbdavioTipas>
<darbdavioBuveinesAdresas i:null="true" />
<darbdavioPagrindineEkonomineVeikla i:null="true" />
<vadovoAsmensKodas>721788222</vadovoAsmensKodas>
<vadovoVardas>tvt</vadovoVardas>
<vadovoPavarde>gtvt</vadovoPavarde>
<vadovoPareigos>5</vadovoPareigos>
<n2:vadovoGimimoDiena xmlns:n2="http://schemas.datacontract.org/2004/07/DssisMP" i:type="d:dateTime">2015-07-22T21:00:00.000Z</n2:vadovoGimimoDiena>
<vadovoLytis>0</vadovoLytis>
<tikrintasObjektas>3</tikrintasObjektas>
<tikrintoObjektoPavadinimas i:null="true" />
<tikrintoObjektoAdresas i:null="true" />
<savivaldybesKodas>46</savivaldybesKodas>
<tikrintaEkonomineVeikla i:null="true" />
<apsilankymuObjekteSkaicius i:null="true" />
<tikrintaNakti>0</tikrintaNakti>
<n3:temineAtaskaita xmlns:n3="http://schemas.datacontract.org/2004/07/DssisMP">
<n3:nr i:null="true" />
<n3:tipas i:type="d:int">18</n3:tipas>
<n3:surasymoData i:type="d:dateTime">2015-07-22T09:53:59.822Z</n3:surasymoData>
<n3:klausimai>
<n3:TAKlausimas>
<n3:kodas i:type="d:string">3183</n3:kodas>
<n3:eilNr i:type="d:string">1.1.</n3:eilNr>
<n3:klausimas i:null="true" />
<n3:atsakymas i:type="d:int">1</n3:atsakymas>
<n3:komentaras i:null="true" />
</n3:TAKlausimas>
<n3:TAKlausimas>
<n3:kodas i:type="d:string">3184</n3:kodas>
<n3:eilNr i:type="d:string">1.1.1.</n3:eilNr>
<n3:klausimas i:null="true" />
<n3:atsakymas i:type="d:int">2</n3:atsakymas>
<n3:komentaras i:null="true" />
</n3:TAKlausimas>
</n3:klausimai>
<n3:rekomendacijos i:type="d:string">Gyghugyb</n3:rekomendacijos>
</n3:temineAtaskaita>
</n0:inspektavimas>
</teiktiTemineAtaskaita>
</v:Body>
</v:Envelope>
My Java code for request creation
List<Questionnaire> questionnaireList = new ArrayList<>();
String METHOD_NAME = "teiktiTemineAtaskaita";
String SOAP_ACTION = "http://tempuri.org/IDssisMP/" + METHOD_NAME;
String A_NAMESPACE = "http://schemas.datacontract.org/2004/07/DssisMP";
String I_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance";
String NAMESPACE = "http://tempuri.org/";
String URL = "http://dvs/dssis_ws_test/DssisMP.svc";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
UserInfo userInfo = UserInfo.getAll().get(0);
request.addProperty("userName", userInfo.getUserName());
request.addProperty("password", userInfo.getPassword());
request.addProperty("uzduotiesNr", taskId);
CompanyInfo ci = CompanyInfo.getByTaskCompanyId(taskId, companyId);
if (ci == null) {
sendResponseFailed(responseHandler);
//starter validation
} else {
//adding all the non-complex properties
SoapObject inspektavimas = new SoapObject(NAMESPACE, "inspektavimas");
if (ci.getInspectationId() != 0) {
inspektavimas.addProperty("inspektavimoNr", ci.getInspectationId());
} else {
inspektavimas.addProperty("inspektavimoNr", null);
}
if (ci.getDateInspectation() != null) {
PropertyInfo p = new PropertyInfo();
p.setNamespace(A_NAMESPACE);
p.setName("inspektavimoPradzia");
p.setType(MarshalDate.class);
p.setValue(ci.getDateInspectation());
inspektavimas.addProperty(p);
} else {
sendResponseFailed(responseHandler);
}
if (ci.getGoalId() != 0) {
inspektavimas.addProperty("inspektavimoTiksloKodas", ci.getGoalId());
} else {
sendResponseFailed(responseHandler);
}
if (ci.getObjectName() != null) {
inspektavimas.addProperty("tikrintoObjektoPavadinimas", ci.getObjectName());
} else { inspektavimas.addProperty("tikrintoObjektoPavadinimas", null);
}
if (ci.getObjectAddress() != null) {
inspektavimas.addProperty("tikrintoObjektoAdresas", ci.getObjectAddress());
} else {
inspektavimas.addProperty("tikrintoObjektoAdresas", null);
}
//...
SoapObject soTemineAtaskaita = new SoapObject(A_NAMESPACE, "temineAtaskaita");
TemineAtaskaita temineAtaskaita = TemineAtaskaita.getByTaskCompanyThemeCode(taskId, companyId, themeCode);
PropertyInfo p = new PropertyInfo();
p.setNamespace(A_NAMESPACE);
p.setName("nr");
if (temineAtaskaita != null && temineAtaskaita.getAtaskaitosNr() != null) {
p.setValue(temineAtaskaita.getAtaskaitosNr());
soTemineAtaskaita.addProperty(p);
} else {
p.setValue(null);
soTemineAtaskaita.addProperty(p);
}
Theme theme = Theme.getByTaskCompanyThemeCode(taskId, companyId, themeCode);
if (theme != null) {
PropertyInfo pType = new PropertyInfo();
pType.setNamespace(A_NAMESPACE);
pType.setName("tipas");
pType.setValue(theme.getThemeCode());
soTemineAtaskaita.addProperty(pType);
PropertyInfo pDate = new PropertyInfo();
pDate.setNamespace(A_NAMESPACE);
pDate.setName("surasymoData");
pDate.setValue(theme.getDate());
pDate.setType(MarshalDate.class);
soTemineAtaskaita.addProperty(pDate);
}
//adding klausimai property which is not seen
SoapObject klausimai = new SoapObject(A_NAMESPACE, "klausimai");
List <Answer> answers = Answer.getByTaskCompanyThemeCode(taskId, companyId, themeCode);
for (Answer answer : answers) {
SoapObject soTAKlausimas = new SoapObject(A_NAMESPACE, "TAKlausimas");
PropertyInfo pCode = new PropertyInfo();
pCode.setNamespace(A_NAMESPACE);
pCode.setName("kodas");
pCode.setValue(answer.getQuestionId());
soTAKlausimas.addProperty(pCode);
Questionnaire questionnaire = Questionnaire.getById(answer.getQuestionId()).get(0);
PropertyInfo pEilNr = new PropertyInfo();
pEilNr.setNamespace(A_NAMESPACE);
pEilNr.setName("eilNr");
pEilNr.setValue(questionnaire.getPosition());
soTAKlausimas.addProperty(pEilNr);
PropertyInfo pKlausimas = new PropertyInfo();
pKlausimas.setNamespace(A_NAMESPACE);
pKlausimas.setName("klausimas");
pKlausimas.setValue(null);
soTAKlausimas.addProperty(pKlausimas);
PropertyInfo pAnswer = new PropertyInfo();
pAnswer.setNamespace(A_NAMESPACE);
pAnswer.setName("atsakymas");
pAnswer.setValue(questionnaire.getPosition());
if (answer.getAnswer() == QuestionItem.STATUS.YES.ordinal())
pAnswer.setValue(1);
else if (answer.getAnswer() == QuestionItem.STATUS.NO.ordinal())
pAnswer.setValue(2);
else if (answer.getAnswer() == QuestionItem.STATUS.UNKNOWN.ordinal())
pAnswer.setValue(3);
else if (answer.getAnswer() == QuestionItem.STATUS.PLAIN.ordinal())
pAnswer.setValue(null);
soTAKlausimas.addProperty(pAnswer);
PropertyInfo pComment = new PropertyInfo();
pComment.setNamespace(A_NAMESPACE);
pComment.setName("komentaras");
if (answer.getComment() != null && !answer.getComment().replace(" ", "").replace(" ", "").isEmpty()) {
pComment.setValue(answer.getComment());
} else {
pComment.setValue(null);
}
soTAKlausimas.addProperty(pComment);
klausimai.addSoapObject(soTAKlausimas);
}
soTemineAtaskaita.addSoapObject(klausimai);
if (theme != null) {
PropertyInfo pSuggestions = new PropertyInfo();
pSuggestions.setNamespace(A_NAMESPACE);
pSuggestions.setName("rekomendacijos");
if (theme.getSuggestions() != null && !theme.getSuggestions().replace(" ", "").replace(" ", "").isEmpty()) {
pSuggestions.setValue(theme.getSuggestions());
} else {
pSuggestions.setValue(null);
}
soTemineAtaskaita.addProperty(pSuggestions);
}
inspektavimas.addSoapObject(soTemineAtaskaita);
request.addSoapObject(inspektavimas);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setAddAdornments(false);
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);
new MarshalDate().register(envelope);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 45 * 1000);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
final SoapObject response = (SoapObject) envelope.getResponse();
****//...****
}

Well as it turns out, I managed to work together with server company, and the problem was ordering inside temineAtaskaita tag. klausimai property should have been the first property to give, althought outside in inspektavimas tag, ordering is not important and that is confusing.
Other problem now occurs is that, everything inside inspektavimas is null because the properties have no namespace. And adding them as PropertyInfo gives a lot of repeated namespaces (n0, n1,...,n20) in XML request Dump and server doesn't handle it. But this is another problem.

Related

Verifying Signed Xml Generated From Java In NET

I have the below XML,
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Response xmlns="http://www.site.ae/g">
<Message xml:id="message">
<Header>
<Service>Read</Service>
<Action>SomeAction</Action>
</Header>
<Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="SomeDataType">
<Status>Success</Status>
<Data>
<Id>123</Id>
</Data>
</Body>
</Message>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<Reference URI="#message">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>SomeValue</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>
SomeValue
</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>
SomeValue
</X509Certificate>
</X509Data>
</KeyInfo>
</Signature>
</Response>
The above XML genereted from a java application. The java application team provided us 3 certificate to verify the above xml. I have created 3 objects in C#,
var clientCert = new X509Certificate2("clientCert.cer");
var intermediateCert = new X509Certificate2("intermediateCert.cer");
var rootCert = new X509Certificate2("rootCert.cer");
One is root, second one is intermediate and third one is certificate. I have created the below code,
var xmlDoc = new XmlDocument();
xmlDoc.PreserveWhitespace = true;
xmlDoc.Load("above.xml");
bool result = VerifyXml(xmlDoc, clientCert);
private static Boolean VerifyXml(XmlDocument Doc, X509Certificate2 Key)
{
// Create a new SignedXml object and pass it
// the XML document class.
var signedXml = new System.Security.Cryptography.Xml.SignedXml(Doc);
// Find the "Signature" node and create a new XmlNodeList object.
XmlNodeList nodeList = Doc.GetElementsByTagName("Signature");
// Throw an exception if no signature was found.
if (nodeList.Count <= 0)
{
throw new CryptographicException("Verification failed: No Signature was found in the document.");
}
// Though it is possible to have multiple signatures on
// an XML document, this app only supports one signature for
// the entire XML document. Throw an exception
// if more than one signature was found.
if (nodeList.Count >= 2)
{
throw new CryptographicException("Verification failed: More that one signature was found for the document.");
}
// Load the first <signature> node.
signedXml.LoadXml((XmlElement)nodeList[0]);
// Check the signature and return the result.
return signedXml.CheckSignature(Key, true);
}
But the above code result is always return false. Is there is something I am missing? Is .NET support verifying the xml generated from java?
Got Answer from
Verify SignatureValue And DigestValue Using Sha256 RSA

Junit 4test result parsing not able to find <failure> tag

here is my Junit test result.xml
I am able to get hold of testsuite and testcase nodes. Now I need to check if test case is failed.
I am using an approach where I check if testcase node has any child and then check if that child is failure node. But when I try to get hold of child node and its type, it returns only the TEXT_NODE and displays failure message text. How do I check if child node is failure?
<?xml version='1.0' encoding='UTF-8' ?>
<testsuite name="com.Test" tests="47" failures="1" errors="0" skipped="0" time="0.425" timestamp="2017-05-25T10:04:14" hostname="localhost">
<properties>
<property name="device" value="Nexus_6_API_22(AVD) - 5.1.1" />
<property name="flavor" value="DEV" />
<property name="project" value="test" />
</properties>
<testcase name="test_1" classname="com.Test" time="0.053" />
<testcase name="test_2" classname="com.Test" time="0.081" />
<testcase name="test_3" classname="com.Test" time="0.0" />
<testcase name="test_4" classname="com.Test" time="0.001">
<failure>junit.framework.ComparisonFailure: expected:<512[]> but was:<512[fed_]>
at junit.framework.Assert.assertEquals(Assert.java:85)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1853)
</failure>
</testcase>
</testsuite>
Well, I figured this out as below, posting for the benefit of others -
//Get a list of test cases with below code -
testCaseList = docElement.getElementsByTagName(TEST_CASE_TAG);
//Iterate through the list and set each item to testElement
// Get Test Case status
TestStatus testCaseStatus = TestStatus.FAILED;
if(testElement.hasChildNodes()) {
//Check if test failed ?
elems = getDirectChildsByTagName(testElement, TEST_FAILURE_TAG);
if(elems != null && elems.size()>0) {
logger.info("failed Tests :"+elems.size());
testCaseStatus = TtuTestStatus.FAILED;
}
//Check if test skipped ?
else {
elems = getDirectChildsByTagName(testElement, TEST_SKIPPED_TAG);
if(elems != null && elems.size()>0) {
logger.info("Skipped Tests :"+elems.size());
testCaseStatus = TtuTestStatus.SKIPPED;
}
}
}
else {
testCaseStatus = TtuTestStatus.PASSED;
}

Cannot access identity claims in custom authorize attribute in MVC application

I am trying to do POC of switching from forms authentication in existing MVC 4 application to claims-based one, but cannot get custom authorize attribute working - have infinite redirect loop ending with known 'bad request' issue because of total cookie size...
And the reason - there is no authenticated identity (and correct Claims collection) in attribute context as I see it in debug despite I see successfully created identity with expected claims collection in SecurityTokenValidated handler.
So, it seems like it is somehow lost after OIDC middleware process it, and not unavailable in attribute context, therefore I cannot further check for 'role' claim.
Maybe I am missing something?
My OWIN Startup:
AntiForgeryConfig.UniqueClaimTypeIdentifier = "sub";
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = CookieAuthenticationDefaults.AuthenticationType
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
AuthenticationType = "oidc",
//AuthenticationMode = AuthenticationMode.Active, // ? https://github.com/IdentityServer/IdentityServer3/issues/1963
Authority = OAuthServerUrl,
ClientId = "my_app",
RedirectUri = MyAppUrl,
ResponseType = "id_token token", //notice, if response type 'token' is requested, IdentityServer stops including the claims in the identity token, though we could set alwaysInclude=true for some scope claims (ex. for role)
Scope = "openid profile roles",
SignInAsAuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
PostLogoutRedirectUri = MyAppUrl,
Notifications = new OpenIdConnectAuthenticationNotifications
{
SecurityTokenValidated = n =>
{
var id = n.AuthenticationTicket.Identity;
//n.OwinContext.Authentication.SignIn(id);
//tried SignIn() explicitly, and even setting HttpContext.Current.User and Thread.CurrentPrincipal to n.AuthenticationTicket.Identity, but without luck
return Task.FromResult(0);
},
RedirectToIdentityProvider = async n =>
{
if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)
{
var result =
await n.OwinContext.Authentication.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationType);
var idToken = result?.Identity.Claims.GetValue("id_token");
if (idToken != null)
{
n.ProtocolMessage.IdTokenHint = idToken;
}
}
await Task.FromResult(0);
}
}
});
My custom attribute inherited from System.Web.Mvc.AuthorizeAttribute:
public class ClaimsAuthorizeAttribute : AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
//var owinContext = HttpContext.Current.GetOwinContext();
if (filterContext.HttpContext.User.Identity.IsAuthenticated)
{
// 403 we know who you are, but you haven't been granted access
filterContext.Result = new HttpStatusCodeResult(System.Net.HttpStatusCode.Forbidden);
}
else
{
// 401 who are you? go login and then try again
filterContext.Result = new HttpUnauthorizedResult();
}
}
}
where filterContext.HttpContext.User.Identity (also tried HttpContext.Current.User and Thread.CurrentPrincipal) has Claims collection with single 'name' claim from LOCAL AUTHORITY issuer (default one?).
I also modified Web.config to disable forms auth:
<authentication mode="None">
...
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="999" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="3" passwordStrengthRegularExpression="" applicationName="Audit" />
<!--<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="999" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="3" passwordStrengthRegularExpression="" applicationName="Audit" />-->
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" applicationName="Audit" />
<!--<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" applicationName="Audit" />-->
</providers>
</profile>
<roleManager enabled="true">
<roleManager enabled="false">
<providers>
<clear />
<add connectionStringName="ApplicationServices" applicationName="Audit" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add applicationName="Audit" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<!--<add connectionStringName="ApplicationServices" applicationName="Audit" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />-->
<!--<add applicationName="MyApp" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />-->
</providers>
</roleManager>
...
<handlers>
<remove name="FormsAuthentication" />
<remove name="RoleManager" />
UPDATE 1: I've migrated app from MVC 4 to the latest MVC 5 hoping it is MVC 4 related issue, but, unfortunately, no difference. Apparently, something wrong with my client application/configuration.

Delete not Working in WCF rest service throwing (405) Method Not Allowed

I have created WCF RESTful service which uses simple database behind it and just trying to working on put, get,post and delete items. Right now post ,put and get is working. But the delete is n't working. Some forums telling that I need to disable the WebDAV module. I did that and then I got PUT to work. But I can not get DELETE to work. Whenever I call DELETE verb through my service I got the following error:
The remote server returned an unexpected response: (405) Method Not Allowed.
Can any one help me on this?
I have not yet found one comprehensive answer for PUT and DELETE being overridden and returning 405s for restful WCF services anywhere else, so I'm going to post it here.
This problem can be addressed easily by simply uninstalling WebDAV from the machine via either the role manager (on a server) or through Add/Remove windows features. If that is an acecceptible approach, you can stop reading now.
The commonly recommended fix here is to simply remove the WebDAV module from your site, appending something like the following to your web.config:
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
</system.webServer>
The problem here is that now your WCF app has no way of knowing how to handle PUT and DELETE at all. So to solve this, some solutions suggest making the follwing modification:
<modules runAllManagedModulesForAllRequests="true">
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
</system.webServer>
This may be satisfactory for most, but I did not like the idea of having our service uselessly loading everything up for every call when it wasn't necessary. So I refined the approach a bit by manually mapping the extensionless URL handler to all HTTP verbs (probably could be refined to just the necessary ones)
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
I only tested this on R2 64 and 7 64, so ymmv. But hopefully this helps.
There seems to have some similar questions on StackOverflow already:
WCF Service 405 Method Not Allowed Exception
WCF The request failed with HTTP status 405: Method Not Allowed
WCF Service Returning "Method Not Allowed"
Hope one of them helps.
I've used the WebChannelFactory approach in the client side to consume the REST service. I've created the Service Reference using the normal "Add Service Reference" approach. This doesn't add [WebGet(UriTemplate = "/")].
After I added these for all Operation on Client side proxy class just like the Service Contract, it started working.
Adding Codes to the Web.config File
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<behaviors >
<serviceBehaviors>
<behavior name="http">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="www">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<services>
<service behaviorConfiguration="http" name="REST.CRUD.Alternativ">
<endpoint address=""
binding="webHttpBinding"
behaviorConfiguration="www"
contract="REST.CRUD.IAlternativ"
bindingConfiguration="rest">
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange">
</endpoint>
</service>
</services>
<bindings>
<webHttpBinding>
<binding allowCookies="true" name="rest">
<security mode="None"></security>
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
<security>
<requestFiltering>
<verbs>
<add verb="GET" allowed="true" />
<add verb="POST" allowed="true" />
<add verb="DELETE" allowed="true" />
<add verb="PUT" allowed="true" />
</verbs>
</requestFiltering>
</security>
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="KendoDB" connectionString="Data Source=(localDB)\v11.0;Initial Catalog=Kendo;Integrated Security=True;Pooling=False" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
PersonDTO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace REST.CRUD
{
public class PersonDTO
{
public int ID { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
}
public class KendoContext : DbContext
{
public KendoContext():base("KendoDB"){}
public DbSet<PersonDTO> PersonDTOs { get; set; }
}
}
IAlternativ.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Web.Services;
namespace REST.CRUD
{
[ServiceContract]
public interface IAlternativ
{
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
List<PersonDTO> GetAll();
[WebInvoke(Method = "GET",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
PersonDTO Get(int ID, string f, string l);
[WebInvoke(Method = "DELETE",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
String Delete(int ID, string f, string l);
[WebInvoke(Method = "PUT",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
String Update(int ID, string f, string l);
}
}
Alternativ.svc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Web.Script.Services;
using System.Web.Services;
namespace REST.CRUD
{
public class Alternativ : IAlternativ
{
public List<PersonDTO> GetAll()
{
var db = new KendoContext();
return db.PersonDTOs.Select(c => c).ToList();
}
public PersonDTO Get(int ID, string f, string l)
{
var db = new KendoContext();
return db.PersonDTOs.Where(c => c.ID == ID).Select(c => c).First();
}
public String Delete(int ID, string f, string l)
{
//Delete Code
return "OK";
}
public String Update(int ID, string f, string l)
{
//Update Code
return "OK";
}
}
}
[Build and Run the WCF Project(F5)].
Add jquery to DOM for test(Paste to Console)
(function() {
if (! window.jQuery ) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = '//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(s);
}
}());
Add functions to Console
function POST(){
$.ajax({
type: "POST", //GET,POST,PUT or DELETE verb
url: "/Alternativ.svc/GetAll", // Location of the service
data: '{"ID":"1"}', //Data to be sent to server
dataType: "json", // content type sent to server
contentType: "application/json; charset=utf-8", //Expected data format from server
processdata: false, //True or False
success: function (response) {
console.log(response);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.statusText);
}
});
}
function GET(){
$.ajax({
type: "GET", //GET,POST,PUT or DELETE verb
url: "/Alternativ.svc/Get", // Location of the service
data: {ID:1}, //Data to be sent to server
dataType: "json", // content type sent to server
contentType: "application/json; charset=utf-8", //Expected data format from server
processdata: true, //True or False
success: function (response) {
console.log(response);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.statusText);
}
});
}
function DELETE(){
$.ajax({
type: "DELETE", //GET,POST,PUT or DELETE verb
url: "/Alternativ.svc/Delete", // Location of the service
data: '{"ID":"1"}', //Data to be sent to server
dataType: "json", // content type sent to server
contentType: "application/json; charset=utf-8", //Expected data format from server
processdata: false, //True or False
success: function (response) {
console.log(response);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.statusText);
}
});
}
function PUT(){
$.ajax({
type: "PUT", //GET,POST,PUT or DELETE verb
url: "/Alternativ.svc/Update", // Location of the service
data: '{"ID":"1"}', //Data to be sent to server
dataType: "json", // content type sent to server
contentType: "application/json; charset=utf-8", //Expected data format from server
processdata: false, //True or False
success: function (response) {
console.log(response);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.statusText);
}
});
}
Call functions
DELETE();
PUT();
GET();
POST();

Return value when internally calling target with phing/phingcall

I am calling a target by means of phingcall command.
I want to pass back a status variable from the called target or at least change the existing value from the calling target.
Goal: I want to branch in my main target controlling logic if the sub target fails which I indicate with a property.
The code below does not work. Any idea how to make it work or an altertive approach for my goal?
Thanks,
Juergen
<target name="main">
<echo>target a</echo>
<echo>${bOk}</echo>
<exec command="echo 1" outputProperty="bOk" />
<echo>bOk is 1: ${bOk}</echo>
<phingcall inheritRefs="true" target="sub">
</phingcall>
<echo>bOk should now be 0: ${bOk}</echo>
</target>
<target name="sub">
<echo>target b</echo>
<echo>bOk is 1: ${bOk}</echo>
<exec command="echo 0" outputProperty="bOk" />
<echo>bOk now is 0: ${bOk}</echo>
</target>
The problem here is that
<echo>bOk should now be 0: ${bOk}</echo>
echos
bOk should now be 0: 1
Even with the great help of #phing IRC I couldn't solve the problem.
I decided to write a custom task to account for data passing between targets:
<?php
require_once "phing/Task.php";
class rvGlobalTask extends Task {
private static $bOk = 1;
private $sMode = null;
private $bValue = null;
private $outputProperty = null;
public function setSMode( $sMode ) {
$this->sMode = $sMode;
}
public function setBValue( $bValue ) {
$this->bValue = $bValue;
}
public function setOutputProperty( $outputProperty ) {
$this->outputProperty = $outputProperty;
}
public function main() {
if ( $this->sMode == "set" ) {
rvGlobalTask::$bOk = $this->bValue;
} else {
$this->project->setProperty(
$this->outputProperty,
rvGlobalTask::$bOk
);
}
}
}
?>
This works fine for my problem. Perhaps someone else finds this useful as well.
Here's how you use an ExecTask to capture output.
<?xml version="1.0" encoding="UTF-8"?>
<project name="example" default="check-composer">
<!-- set a property to contain the output -->
<property name="whichComposer" value="" />
<!-- check if composer (getcomposer.org) is installed globally -->
<target name="check-composer">
<!-- put the output of "which" in our property -->
<exec command="which composer" outputProperty="whichComposer" />
<!-- act on what we found out -->
<if>
<contains string="${whichComposer}" substring="composer" />
<then>
<echo>Composer installed at ${whichComposer}</echo>
</then>
<else>
<echo message="better install composer. ${whichComposer}"/>
</else>
</if>
</target>
</project>