Error obtaining the response from a Web Service call - web-services

I am trying to consume a Web Service and, though apparently all my parameters seem to be okay, I keep getting an erro page as response instead of an array of bytes which is what I am expecting and what the WebService is supposed to return.
My objective is to Seal a file in order to make them only readable for the right people. I am using the IRM Oracle Web Services to acomplish that, but, though all my parameters semm alright, I can't get the reponse properly.
Acording to the Oraclel support, my request is fine, so it must be something on IIS I guess. Any help?
Exception Message:
The content type multipart/related;start="";type="application/xop+xml";boundary="uuid:ab73a894-eaf4-4293-aa4e-c3358b95ec73";start-info="text/xml" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 748 bytes of the response were: '--uuid:ab73a894-eaf4-4293-aa4e-c3358b95ec73 Content-Id: Content-Type: application/xop+xml;charset=utf-8;type="text/xml" Content-Transfer-Encoding: binary '.
Exception Stacktrace:
Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at HTMLToPDFComponenteConverter.sealing_services.SealingServices.Seal(SealRequest request) at HTMLToPDFComponenteConverter.sealing_services.SealingServicesClient.HTMLToPDFComponenteConverter.sealing_services.SealingServices.Seal(SealRequest request) at HTMLToPDFComponenteConverter.sealing_services.SealingServicesClient.Seal(Byte[] stream, String mimeType, SealingOptions options) at HTMLToPDFComponenteConverter.ConvertToPDF.Page_Load(Object sender, EventArgs e)
Exception Data:
System.Collections.ListDictionaryInternal
Exception Source:
mscorlib
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "application/vnd.sealedmedia.softseal.pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=Relatorio.spdf");
SealingServicesClient sealingServicesClient =
new SealingServicesClient("SealingServices");
sealingServicesClient.ClientCredentials.UserName.UserName =
ConfigurationManager.AppSettings["Irm-user"];
sealingServicesClient.ClientCredentials.UserName.Password =
ConfigurationManager.AppSettings["Irm-password"];
// Create the classification details used in the sealing options
SealingOptions sealingOptions = new SealingOptions();
// This just set several parameters which the WebService validates. (They're all okay)
sealingOptions.classification = GetClassificationSetUp();
String mimeType = "application/pdf";
// Here is where everything goes wrong. I keep getting an error message.
byte[] sealedFile = sealingServicesClient.Seal(file, mimeType, sealingOptions);
if (sealedFile != null && sealedFile.Length > 0)
{
Response.AddHeader("Content-Length", sealedFile.Length.ToString());
Response.BinaryWrite(sealedFile);
Response.Flush();
Response.End();
}
Meu WebConfig está desse jeito:
<system.serviceModel>
<client>
<endpoint address="https://url:porta/irm_sealing/sealing_services"
binding="basicHttpBinding" bindingConfiguration="SealingServicesBinding"
contract="sealing_services.SealingServices" name="SealingServices"
behaviorConfiguration="IrmSealingAbril">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="IrmSealingAbril">
<clientCredentials>
<clientCertificate storeLocation="LocalMachine"
storeName="Root"
x509FindType="FindByThumbprint"
findValue="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX">
</clientCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="SealingServicesBinding" closeTimeout="00:05:00"
openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2097152" maxBufferPoolSize="524288" maxReceivedMessageSize="2097152"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="Basic" realm="weblogic" />
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
Where am I going wrong?
Additional information: The request apparently is correct as confirmed by oracle support. However, I can't get the returning response. I thought it could be something related to the IIS, but I do not have mush skill at configuring it.
Thanks in advance.

I found the answer for my problem here:
Error consuming webservice, content type "application/xop+xml" does not match expected type "text/xml"
Thanks anyway

Related

Calling Web Service error "The remote server returned an unexpected response: (502) Connection refused."

Dears,
I have the following web service from client to call:
http://ajec.proxym-it.net/Ajec_sso_api/authenticate.wsdl
When I try to consume it, I got the this error :
The remote server returned an unexpected response: (502) Connection refused.
The inner exception is: {"The remote server returned an error: (502) Bad Gateway."}
Here is my code:
AuthenticateService.AuthenticatePortClient oAuthenticatePortClient = new AuthenticateService.AuthenticatePortClient();
AuthenticateService.authenticateRequest oauthenticateRequest = new AuthenticateService.authenticateRequest();
oauthenticateRequest.serviceId = "MobileTeam";
oauthenticateRequest.serviceKey = "AJEC1";
oauthenticateRequest.userName = "MMelhem";
oauthenticateRequest.password = "P#$$w0rd";
AuthenticateService.authenticateResponse oregisterUserResponse = oAuthenticatePortClient.authenticate(oauthenticateRequest);
and the web.config is:
<configuration>
<system.net>
<defaultProxy>
<proxy usesystemdefault="False" bypassonlocal="False" />
</defaultProxy>
</system.net>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="AuthenticatePortSoap11" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://172.16.0.82:80/Ajec_sso_api/authenticate"
binding="basicHttpBinding" bindingConfiguration="AuthenticatePortSoap11"
contract="AuthenticateService.AuthenticatePort" name="AuthenticatePortSoap11" />
</client>
</system.serviceModel>
</configuration>
What tool did you use to generate your client code (or hand-coded it)?
I used wsimport and I got slightly different code than yours. Since the IP seems to be in local domain (172.16.0.82), I couldn't test it. If you are interested, you could try it.
I used wsimport to generate/compile client class files:
wsimport -keep http://ajec.proxym-it.net/Ajec_sso_api/authenticate.wsdl
Then coded the client like this:
import com.ajec_sso.authenticate.*;
public class TClient {
static AuthenticatePortService service = new AuthenticatePortService();
public static void main(String[] args) {
try {
AuthenticatePort port = service.getAuthenticatePortSoap11();
AuthenticateRequest req = new AuthenticateRequest();
AuthenticateResponse res = new AuthenticateResponse();
req.setServiceId("MobileTeam");
req.setServiceKey("AJEC1");
req.setUserName("MMelhem");
req.setPassword("P#$$w0rd");
res = port.authenticate(req);
} catch(Exception e) {
e.printStackTrace();
}
}
}
Compiled like this (the generated com directory is in current directory).
javac TClient.java
I solved the problem by replace the endpoint address from
http://172.16.0.82:80/Ajec_sso_api/authenticate
to
http://ajec.proxym-it.net/Ajec_sso_api/authenticate

Call WebService in https

I create a webService to generate pdf file. In debug mode with VisualStudio 2012. It's Ok. I can call it from other IntranetSite.
I try to put it on my test server. But I need to add https instead of http.
I find this
I try to adapted like this my web.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="GenerationCourriersSoap" >
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="Certificate" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="secureBehaviours">
<serviceMetadata httpsGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<client>
<endpoint address="https://localhost:52999/GenerationCourrier.asmx"
binding="basicHttpBinding" bindingConfiguration="GenerationCourriersSoap"
contract="WSCourrier.GenerationCourriersSoap" name="GenerationCourriersSoap" />
</client>
</system.serviceModel>
But I've message
Unable to establish a trust for the secure channel SSL / TLS with authority 'localhost: 52999'.
I used an auto-certicate buid by IIS directly.
I verify, this certificate is on my root and secure folder
Someone have an idea?
Finally I find this enter link description here
It seems good. now I can reach the webService.
The Idea is to force the validation of all certificate. Just the time of test period like that
Imports System
Imports System.Net
Imports System.Security.Cryptography.X509Certificates
Public Class clsSSL
Public Function AcceptAllCertifications(ByVal sender As Object, ByVal certification As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal chain As System.Security.Cryptography.X509Certificates.X509Chain, ByVal sslPolicyErrors As System.Net.Security.SslPolicyErrors) As Boolean
Return True
End Function
End Class
And call function just before call WebService function
ServicePointManager.ServerCertificateValidationCallback = AddressOf AcceptAllCertifications

Axis2 Adb Client Basic Auth over https secure url

I have serached this question on Stackoverflow and found some similar questions but none of them solved my issue. I have compiled all the "proposed" solution but NOTHING works :-(
I have a wsdl and I generated the client code using adb client(Axis 2). The wsdl says that this request will be sent over Https url. I able to successfully create a stub using wsdl to java. However I am not sure how to Basic authentication. The documentation which tells me the details also says that I user name and pwd should be encoded using Base64.
The authentication method used is HTTP Basic . The user name and
password will need to be encoded in a base64 format – UTF8 character
set.
Example: Username:Password = “VXNlcm5hbWU6UGFzc3dvcmQ=”
BTW I have tried this wsdl in SOAP UI and and I am getting correct response but some how my java code won't work
Now Here is the wsdl
<?xml version="1.0" encoding="UTF-8"?>
<definitions targetNamespace="urn:OTSB2B" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:OTSB2B" xmlns:intf="urn:OTSB2B" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema targetNamespace="urn:OTSB2B" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:urn="urn:OTSB2B">
<simpleType name="tn">
<restriction base="string">
<length value="10"/>
</restriction>
</simpleType>
<simpleType name="prov">
<restriction base="string">
<length value="2"/>
<enumeration value="on"/>
<enumeration value="qc"/>
</restriction>
</simpleType>
<element name="getPresaleByTN">
<complexType>
<sequence>
<element name="tn" type="urn:tn"/>
<element name="prov" type="urn:prov"/>
</sequence>
</complexType>
</element>
<element name="getPresaleByTNReturn" type="xsd:string"/>
<element name="isAlive"/>
<element name="isAliveReturn" type="xsd:boolean"/>
</schema>
</wsdl:types>
<message name="isAliveRequest">
<part element="impl:isAlive" name="isAlive"/>
</message>
<message name="getPresaleByTNRequest">
<part element="impl:getPresaleByTN" name="getPresaleByTN"/>
</message>
<message name="isAliveResponse">
<part element="impl:isAliveReturn" name="isAliveReturn"/>
</message>
<message name="getPresaleByTNResponse">
<part element="impl:getPresaleByTNReturn" name="getPresaleByTNReturn"/>
</message>
<portType name="GetPresaleByTN">
<operation name="getPresaleByTN">
<input message="impl:getPresaleByTNRequest" name="getPresaleByTNRequest"/>
<output message="impl:getPresaleByTNResponse" name="getPresaleByTNResponse"/>
</operation>
<operation name="isAlive">
<input message="impl:isAliveRequest" name="isAliveRequest"/>
<output message="impl:isAliveResponse" name="isAliveResponse"/>
</operation>
</portType>
<binding name="DominoSoapBinding" type="impl:GetPresaleByTN">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getPresaleByTN">
<wsdlsoap:operation soapAction=""/>
<input name="getPresaleByTNRequest">
<wsdlsoap:body use="literal"/>
</input>
<output name="getPresaleByTNResponse">
<wsdlsoap:body use="literal"/>
</output>
</operation>
<operation name="isAlive">
<wsdlsoap:operation soapAction=""/>
<input name="isAliveRequest">
<wsdlsoap:body use="literal"/>
</input>
<output name="isAliveResponse">
<wsdlsoap:body use="literal"/>
</output>
</operation>
</binding>
<service name="GetPresaleByTNService">
<port binding="impl:DominoSoapBinding" name="Domino">
<wsdlsoap:address location="https://b2b.ivv.bell.ca/ots-qualification-service-tn"/>
</port>
</service>
</definitions>
I have tried this:
GetPresaleByTNServiceStub stub = new GetPresaleByTNServiceStub();
ServiceClient client = stub._getServiceClient();
client.addStringHeader(new QName("userName"), "XXX");
client.addStringHeader(new QName("password"), "YYYYYYYY");
GetPresaleByTNServiceStub.GetPresaleByTN request = new GetPresaleByTN();
Tn tn = new Tn();
tn.setTn("4164390001");
request.setTn(tn);
request.setProv(Prov.on);
GetPresaleByTNReturn response = stub.getPresaleByTN(request);
System.out.println(response.getGetPresaleByTNReturn());
This gives me following error:
org.apache.axis2.AxisFault: Failed to add string header, you have to
have namespaceURI for the QName at
org.apache.axis2.client.ServiceClient.addStringHeader(ServiceClient.java:434)
at com.dinesh.bellAxis.App.main(App.java:30)
Then I tried this
GetPresaleByTNServiceStub stub = new GetPresaleByTNServiceStub();
ServiceClient client = stub._getServiceClient();
HttpTransportProperties.Authenticator basicAuth = new HttpTransportProperties.Authenticator();
basicAuth.setUsername("XXX");
basicAuth.setPassword("CCCCC");
basicAuth.setPreemptiveAuthentication(true);
stub._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, basicAuth);
GetPresaleByTNServiceStub.GetPresaleByTN request = new GetPresaleByTN();
Tn tn = new Tn();
tn.setTn("4164390001");
request.setTn(tn);
request.setProv(Prov.on);
GetPresaleByTNReturn response = stub.getPresaleByTN(request);
System.out.println(response.getGetPresaleByTNReturn());
This gives me the following error:
org.apache.axis2.AxisFault: Transport level information does not match
with SOAP Message namespace URI at
org.apache.axis2.AxisFault.makeFault(AxisFault.java:430) at
org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:90)
at
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:353)
at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at
com.acn.client.GetPresaleByTNServiceStub.getPresaleByTN(GetPresaleByTNServiceStub.java:460)
Next I tried this: which I think is incorrect as it WS Security and not basic auth but what the heck I exhausted all my options
GetPresaleByTNServiceStub stub = new GetPresaleByTNServiceStub();
ServiceClient client = stub._getServiceClient();
OMFactory omFactory = OMAbstractFactory.getOMFactory();
OMElement omSecurityElement = omFactory.createOMElement(new QName( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", "wsse"), null);
OMElement omusertoken = omFactory.createOMElement(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "UsernameToken", "wsu"), null);
OMElement omuserName = omFactory.createOMElement(new QName("", "Username", "wsse"), null);
omuserName.setText("XXXX");
OMElement omPassword = omFactory.createOMElement(new QName("", "Password", "wsse"), null);
omPassword.addAttribute("Type","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText",null );
omPassword.setText("YYYYYYY");
omusertoken.addChild(omuserName);
omusertoken.addChild(omPassword);
omSecurityElement.addChild(omusertoken);
stub._getServiceClient().addHeader(omSecurityElement);
GetPresaleByTNServiceStub.GetPresaleByTN request = new GetPresaleByTN();
Tn tn = new Tn();
tn.setTn("4164390001");
request.setTn(tn);
request.setProv(Prov.on);
GetPresaleByTNReturn response = stub.getPresaleByTN(request);
System.out.println(response.getGetPresaleByTNReturn());
This gives the following error:
Exception in thread "main" java.lang.IllegalArgumentException: Cannot
create a prefixed element with an empty namespace name at
org.apache.axiom.om.impl.llom.OMElementImpl.handleNamespace(OMElementImpl.java:186)
at
org.apache.axiom.om.impl.llom.OMElementImpl.(OMElementImpl.java:161)
at
org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory.createOMElement(OMLinkedListImplFactory.java:126)
at com.dinesh.bellAxis.App2.main(App2.java:37)
I am not sure what to do next and have checked all the documentation on Apache Axis2 and googled all over the place but could get the code to work.
Any suggestions
Code fragments 1 and 3 don't work because they attempt to create a message that is invalid with respect to SOAP (fragment 1) or XML (fragment 3). Anyway, they attempt to add SOAP headers to the message, which is not what basic auth is about.
Code fragment 2 looks correct. From the stack trace of the exception (more precisely the presence of the handleResponse method) you can see that there is an issue with the response. The error message likely indicates that the content type of the response doesn't match the SOAP version actually used in the response. This means that there is a problem with the service, not with the client.
I found the answer after a lot of trial and error and going over SAAj tutorial on Oracle website.
I able to do Basic authentication using this
String authorization = new sun.misc.BASE64Encoder().encode((“myUserName”+”:”+”myPassword”).getBytes());
headers.addHeader(“Authorization”, “Basic ” + authorization);
Here's the complete tutorial - http://www.javahabit.com/2014/10/17/quick-tutorial-saaj-api/

POST Method in wcf Rest Service

i am getting the same error:
protected void Button1_Click(object sender, EventArgs e)
{
BasicHttpBinding binding = new BasicHttpBinding();
binding.ReaderQuotas.MaxStringContentLength = 2000000;
binding.MaxBufferSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;
binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
binding.Security.Transport.ClientCredentialTypeHttpClientCredentialType.Windows;
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.CloseTimeout = new TimeSpan(4, 0, 0);
binding.OpenTimeout=new TimeSpan(4, 0, 0);
binding.ReceiveTimeout=new TimeSpan(2, 0, 0);
binding.SendTimeout = new TimeSpan(5, 0, 0);
EndpointAddress endpoint = new EndpointAddress(new Uri("http://localhost:35798/RestServiceImpl.svc"));
RestPostService.RestServiceImplClient obj = new RestPostService.RestServiceImplClient(binding, endpoint);
RestPostService.EmailDetails obj1 = new RestPostService.EmailDetails();
obj.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
RestPostService.EmailDetails obj2=obj.SendMail(obj1);
}
**web.config**
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"/>
</webHttpBinding>
</bindings>
<services>
<service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
<endpoint address ="http://localhost:35798/RestServiceImpl" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="webHttp"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="webHttp">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
What changes should i made in order to make the code working.
Error: The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
Please help in the indiacted issue.
You are using the wrong WCF binding in you code. The config XML shows the WCF service using the WebHttpBinding. Refactor your client creation code to something like:
WebHttpBinding binding = new WebHttpBinding();
// The rest of the configuration
Don't know if all the properties you are setting will be valid for this binding but the compiler will know :)

Adding web service bindings into SharePoint web.config using SPWebConfigModification

I have a SharePoint web part which uses a WCF service. To be able to consume the web service in my web part, I need to modify the SharePoint web.config to include bindings and end points.
What's the best way to do this?
This was very useful but it missed a bit. Whereas the code can be deployed, it can't be retracted because a name wasn't assigned.
Use:
modification.Name = "bindings";
Also, having said that this is bindings, you (probably) can't still can't apply the settings if there are already settings there for:
serviceHostingEnvironment aspNetCompatibilityEnabled="true"
... inside the system.serviceModel
I've used the technique to insert the bindings and then the client end point gets inserted separately as this can change according to installation and in my case is set via a sharepoint list entry.
To be able to do this, I put my web service configuration into a text file as a template. The text file (BindingTemplate.txt) content is as the following:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_AuthenticationInterface" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://{0}/MyWebService/AuthenticationService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_AuthenticationInterface" contract="AuthenticationService.AuthenticationInterface" name="BasicHttpBinding_AuthenticationInterface" />
</client>
I used the C# following code to modify the web.config:
string content;
string WebServiceServer = "example.com"; // <=== your host-name here
using (TextReader tr = File.OpenText(bindingFilePath))
{
content = String.Format(tr.ReadToEnd(), WebServiceServer);
}
SPWebConfigModification modification = new SPWebConfigModification("system.serviceModel", "configuration");
modification.Value = content;
modification.Sequence = 0;
modification.Type =SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
modification.Owner = OWNER_CONSTANT;
webApp.WebConfigModifications.Add(modification);
I spent some time figuring it out. Hope this will help someone.