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
Related
I managed to create a web service with self signed SSL through IIS. It's settings at first are set to Client Certificate to none and none required SSL. It is accessible by that time threw web browser and mobile web reference.
Web Browser
Xamarin Web Reference
But when I set the SSL settings to required, it is now forbidden in both. What am I missing in settings for SSL Configuration?
SSL Settings Thru IIS
Web Browser Forbidden Access
Xamarin Web Reference Forbidden Access
WebConfig
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="constring" providerName="System.Data.SqlClient" connectionString="Data Source = source;Initial Catalog = dbname; User ID = user; Password = pw" />
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation targetFramework="4.5" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="10485760" name="SecureHttpBinding">
<readerQuotas maxStringContentLength="10485760"></readerQuotas>
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
To access web service via HTTPS in web browser, I followed this link for creating temporary client certificate but I changed the step #5 to this command
makecert -sk MyKeyName -iv RootCaClientTest.pvk -n "CN=tempClientcert" -ic RootCaClientTest.cer -sr localmachine -ss my -sky exchange -pe
I changed the currentuser to localmachine and signature to exchange so that it will be in personal certificate store. When you access the site again, it will ask for client certificate and you can choose it to proceed.
For the main problem to access the service in visual studio xamarin via web reference (which is forbidden somehow).
I found this link to solve the forbidden problem. You can see the second post of (c)MarkoOkram for the solution.
"I am solved problem by saving web browser .wsdl and .xsd files on file system, change reference in those files to matching files. Than i succesfully add reference in visual studio to that file system .wsdl file." -(c) MarkoOkram
I downloaded the file WSDL and XSDs written in WSDL then retarget the filepath to their respective directories and it's done.
update: I also tried to import singleWSDL and it works without editing for xsd's
I have one console application (i.e. Project1/Solution1).I am calling one web service (.asmx) from console application which is in separate project (i.e. Project1/Soloution2)
Through single web method there is call to two different business class methods (i.e. Project2/Soloution2) which in turn call two different external wcf services.
I am programmatically creating the endpoint and binding elements to call the wcf methods.
EndpointAddress ed = new EndpointAddress(rtd.WebServiceUrl);
BasicHttpBinding binding = new BasicHttpBinding("BasicHttpBinding_TestService");
ServiceClient client = new ServiceClient(binding, ed);
string response = client.Getdetails(string input1, string input2)
I am getting error "No elements matching the key 'BasicHttpBinding_TestService’ were found in the configuration element collection" although I have added this configuration
in my app.config file.
Section in my app.config file
<binding name="BasicHttpBinding_TestService" closeTimeout="00:00:05"
openTimeout="00:00:05" receiveTimeout="00:00:15" sendTimeout="00:00:05"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2047487456" maxBufferPoolSize="524288" maxReceivedMessageSize="2047487456"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2047487456"
maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
Even I added this in the web.config file where my web method resides (i.e. Project1/Soloution2) and in the calling console application's app.config file.
Take a look at the bindings in your web.config files from your external WCF service. The bindings in the Web.config of the WCF application and the app.config of the client application must match in order for that binding configuration to work.
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 :)
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.
I'm trying to setup an SAP Web Service that would be consumed by a .NET application. Thinking it was simple, I had set the Service up in SAP to use HTTP. I right-click on the "Service References" in the .NET Project Tree, and choose "Add Service Reference...", Enter the WSDL URL locally hosted on our servers, and press Go, then select the endpoint, then press OK.
I opened up the app.config file to find that it says <httpsTransport> instead of <httpTransport>, although I set it up to use HTTP.
<system.serviceModel>
<bindings>
<customBinding>
<binding name="ZHR_RECRUITNEW1">
<!--WsdlImporter encountered unrecognized policy assertions in ServiceDescription 'urn:sap-com:document:sap:soap:functions:mc-style':-->
<!-- <wsdl:binding name='ZHR_RECRUITNEW'> -->
<!-- <wsaw:UsingAddressing xmlns:wsaw="http://schemas.xmlsoap.org/ws/2004/08/addressing">..</wsaw:UsingAddressing> -->
<!-- <saptrnbnd:OptimizedXMLTransfer xmlns:saptrnbnd="http://www.sap.com/webas/710/soap/features/transportbinding/">..</saptrnbnd:OptimizedXMLTransfer> -->
<!-- <sapattahnd:Enabled xmlns:sapattahnd="http://www.sap.com/710/features/attachment/">..</sapattahnd:Enabled> -->
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap11" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" requireClientCertificate="false" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://<host>:8000/sap/bc/srt/rfc/sap/zhr_recruitnew/300/zhr_recruitnew/zhr_recruitnew"
binding="customBinding" bindingConfiguration="ZHR_RECRUITNEW1"
contract="ServiceReference2.ZHR_RECRUITNEW" name="ZHR_RECRUITNEW1" />
</client>
</system.serviceModel>
So, for it to work "properly", I have to rename that xml tag from httpsTransport to httpTransport and remove the attribute requireClientCertificate="false"
So, I go into SAP to set up the Service to use HTTPS, and then go back to the .NET project and re-add that service, to get this error message:
Could not establish trust relationship for the SSL/TLS secure channel with authority '<host>:<portnumber>'.
I'm curious as to whether that comment "WsdlImporter encountered unrecognized policy assertions" in the config file has to do anything with that info being misread from SAP
Could not establish trust relationship for the SSL/TLS secure channel with authority ':'.
You get this because the certificate on the service provider isn't in your trusted root certificates locally.
You can add this to your code(before anything else) to ignore it:
System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);