Placeholder URL for SharePoint web services - c#

tl;dr
Below is the app.config from my class library which simplifies file manipulation in SharePoint. The endpoint addresses point at an arbitrary site but are set dynamically to the correct site when the library is used.
Will the DLL still work if the arbitrary address changes/ceases to exist?
Can I package my class library to dynamically add endpoint's and binding's to the project that references the library (Based on the site they interact with)?
Details
I created a class library in C# to simplify access to SharePoint sites via the Copy and Lists web services. By passing in the site URL and other data, the end user can easily upload, download, and manipulate files in SharePoint. When they pass the site URL, I dynamically set the Copy or Lists reference to use that URL. While this works out fine, I have two questions:
I must include a reference in the app.config/web.config to one SharePoint server to get the web service details when developing. If that URL changes or ceases to exist, then will my library fail?
Even though the DLL is included when referenced, the app.config containing the basicHttpBinding and endpoint addresses is not included. Is there a way to add that data in the web.config/app.config of the project that is using the class library?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
</appSettings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="CopySoap" maxReceivedMessageSize="419430400">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="ListsSoap">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.example.com/subsite/_vti_bin/copy.asmx"
binding="basicHttpBinding" bindingConfiguration="CopySoap"
contract="CopyService.CopySoap" name="CopySoap" />
<endpoint address="http://www.example.com/subsite/_vti_bin/Lists.asmx"
binding="basicHttpBinding" bindingConfiguration="ListsSoap"
contract="ListsService.ListsSoap" name="ListsSoap" />
</client>
</system.serviceModel>
</configuration>
Thanks for your time.

My Answers
If you are writing it in App.Config, there is no way it's hard coded. It's a config file. You can change it whenever you want and you do not need to rebuild your project. I hope for you are checking wheather the Site/Server exists before proceeding with functionality. If the server/site does not exist - handle it gracefully and show appropiate message so that a user can go and change the config file to point it to correct server
You can simply add the configs required for your service in the "Referenced Project"'s web or app.config. Since your DLL in running in the context of the Referenced Project, it would pcik the necessary values from its app/web.config

Related

Access WCF by clicking a hyperlink

Hi I was wondering if it is possible to access a WCF service by clicking a hyperlink like the following from a browser: https://MyServer/MyWebservice.svc/GetUpdate?id=10
Thanks in advance.
If you want to publish a Http-mode WCF service, you could refer to the following answer.
How can I use a WCF Service?
if you want to host the service via HTTPS protocol, you need to add the following configuration and set up a certificate in IIS.
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="mybinding">
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</webHttpBinding>
</bindings>
Feel free to let me know if there is anything I can help with.

Azure Cloud Service Instance Keep Recycling after deployment - SDK 2.6

I have ASP.NET MVC 5 project, referenced a SOAP Service from one of our client. I added the service using Visual Studio and, it requires a username/password authentication.
Here is the configuration part for the SOAP reference from the Web.Config file.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SoapBinding">
<readerQuotas maxDepth="32" maxStringContentLength="65536" 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="*** SOAP URL ***" binding="basicHttpBinding" bindingConfiguration="SoapBinding" contract="** ContactName**" name="name1">
<headers>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>** username**</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">** password**</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</headers>
</endpoint>
</client>
</system.serviceModel>
Then, I created Azure Cloud Project, and publish the project from Visual Studio, but unfortunately the Instance is keep recycling.
The moment, I remove the <System.ServiceModel>, and remove the SOAP reference and redeploy; the web application works fine.
The MVC project run perfectly on local referencing the SOAP service, and I am able to communicate with the SOAP service.
Note: I have RDC to the azure instance and browse the application from IIS, I can see the page is loading and result are displaying from the SOAP service, but the Instance is keep recycling on Azure dashboard; therefore it won't be accessed from outside.
Any help will be appreciated. Thank you!

class library application not using the app.config file

I am facing problem while consuming the webservice and making an web service call.
I am creating the class library application which will generate the dll and this dll will be used by some other application to connect the webservice.I have received the WSDL file from third part and I "Add a service reference" and used all the proxy classes to create my soap body. Now I have two issues I need to add the wsse:security header to my soap message like below
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>username</wsse:Username>
<wsse:Password>password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
To handle this and to connect the webserivce endpoint address have modified my app.config file (which got generated when add service reference) to include this as header tag. below is my app.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ICMS-Http-WSBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://devs-dp-in.wellpoint.com/Claims/2.0/Get_iHealthICMS_Results"
binding="basicHttpBinding" bindingConfiguration="ICMS-Http-WSBinding"
contract="Ihlth_Service1.ICMSHttpWSPortType" name="ICMS-Http-WSPortType">
<headers>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>username</wsse:Username>
<wsse:Password>password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</headers>
</endpoint >
</client>
</system.serviceModel>
</configuration>
When I tried to initialize my client as below I am facing the error as Could not find endpoint element with name 'ICMS-Http-WSPortType' and contract 'Ihlth_Service.ICMSHttpWSPortType' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element
Service.CMSHttpWSPortTypeClient Client = new Service.CMSHttpWSPortTypeClient("ICMS-Http-WSPortType");
I modified my code to create a binding and endpoint address inside the code and pass to the client then it worked fine but again faced issue at the security header missing as I provided the security information in app.config file
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
EndpointAddress address = new EndpointAddress("https://devs-dp-in.wellpoint.com/Claims/2.0/Get_iHealthICMS_Results");
is there any way that I can read the app.config file or my code refer that config file to get the information rather giving inside the code.
This entire code is working fine in the windows application by reading the app.config file but not in the class library application is there any reason behind that ?
Any one please give some idea
The app.config of a DLL is, at best, a reminder of what needs to be placed in the app.config of the EXE that consumes your DLL or the web.config of a website that consumes your DLL.
It's not actually used by default by the configuration system, and it's slightly unfortunate that some tooling (such as Add Service Reference) will create one in a class library project and give no warning about this.

C# SOAP Client use TLS instead of SSL 3.0

I have a C# application which is using Travelport Universal API interfaces through SOAP communication.
In C# I used the wsdls for generating the SOAP client.
I have this config settings for HTTPS connection (this was generated by Visual Studio from WSDL):
<system.serviceModel>
<bindings>
<basicHttpsBinding>
<binding name="AirLowFareSearchBinding" maxBufferSize="2097152" maxReceivedMessageSize="2097152">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpsBinding>
</bindings>
<client>
<endpoint address="https://emea.universal-api.travelport.com/B2BGateway/connect/uAPI/AirService" binding="basicHttpsBinding" bindingConfiguration="AirLowFareSearchBinding" contract="AirServiceReference.AirLowFareSearchPortType" name="AirLowFareSearchPort" />
</client>
About this SSL3.0 vulnerability Travelport want to disabling SSL3, and I could use just over TLS.
My question is what should I change on this config, or should I change anything for TLS connection on https instead of SSL3.
In you code before calling to the service:
system.Net.ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls12;
Here is a blog post Here

How do I set up WCF to consume Oracle web service using HTTPS?

I am currently using WCF to connect to our Java web services via the following configuration:
<bindings>
<basicHttpBinding>
<binding name="WebServicePortBindingHttp" maxReceivedMessageSize="500000">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://host:port/url" binding="basicHttpBinding" bindingConfiguration="WebServicePortBindingHttp" contract="Namespace.WSPort" name="WebServicePort" />
</client>
This is using normal HTTP. Even so, the server wouldn't authorize me until I manually added the WSSE headers using the method suggested in this answer. Once I started doing that, I was able to consume the web services without trouble.
On some of our environments, however, the server that my C# client must connect to uses HTTPS instead of HTTP. For this, the configuration given above does not work. To begin with, I had to change the security mode from TransportCredentialOnly to Transport, like so:
<binding name="WebServicePortBindingHttp" maxReceivedMessageSize="500000">
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
</security>
</binding>
I have tried numerous variations on these settings, however all that happens is the request times out. When I use Wireshark to trace the communication, I can see that the server is actually responding, but I can't interpret its response as the text appears garbled (I guess because it is encrypted).
This is what the binding configuration looks like that is automatically created by Visual Studio when I import the WSDL:
<customBinding>
<binding name="HTTPSoapBinding">
<textMessageEncoding messageVersion="Soap11" />
<httpsTransport />
</binding>
</customBinding>
But this still does not change the behaviour. It would appear that Microsoft and Oracle technologies do not simply interoperate.
Please advise.
I'm an idiot. There was something else causing the timeout! This configuration actually works:
<binding name="WebServicePortBindingHttp" maxReceivedMessageSize="500000">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
Strangely enough, now that I have identified the cause of my timeout, the webservice seems to accept just about any value for clientCredentialType (so far I have tried None, Basic and Windows, and all of them work). Could anyone explain this?
I apologize if I wasted anyone's time with this question.

Categories

Resources