How to create a SVC page that is accessed directly - wcf

According to my documentation 3rd party device connects to address:
https://Enrollment.myweb.com/EnrollmentServer/Register.svc
Header:
POST /EnrollmentServer/Register.svc HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
User-Agent: Windows Phone 8 Enrollment Client
Host: Enrollment.myweb.com
..
<?xml version="1.0"?>
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
...
</s:Envelope>
Some samples of SVC I have seen all have some additional methods that they call, like Service.svc/GetData and calling directly Service.svc I will get the standard response:
You have created a service.
To test this service, you will need to create a client and use it to call the service.
Can anyone point me to the correct documentation or even better - to a simple sample in C# on how to create SVC page that can be accessed directly and that would return some XML text?

You can go for REST Service.
See this: http://beyondrelational.com/blogs/dhananjaykumar/archive/2011/02/01/walkthrough-creating-rest-service-in-wcf-4-0.aspx
Also, can use Web API. http://www.asp.net/web-api

Related

Unable to test an API in JMeter where I need to upload a file

can someone please help me with uploading a file on JMeter I feel its very tricky thing...
let me share the screen shot of what I've done
enter image description here
Its failing with below error:
Thread Name:jp#gc - Ultimate Thread Group 2-4
Sample Start:2021-02-04 17:28:44 IST
Load time:562
Connect Time:0
Latency:562
Size in bytes:595
Sent bytes:84568
Headers size in bytes:446
Body size in bytes:149
Sample Count:1
Error Count:1
Data type ("text"|"bin"|""):text
Response code:500
Response message:
HTTPSampleResult fields:
ContentType: application/json
DataEncoding: null
Response Body:
{"timestamp":"2021-02-04T11:58:45.482+00:00","status":500,"error":"Internal Server Error","message":"","path":"/pps/storage/upload-image"}
Request Body:
POST https://pixelperfectdevexternal.useready.com/pps/storage/upload-image
POST data:
--axOhwnTOrVj2VWGGuxcaqfjgHwGQKsTFl
Content-Disposition: form-data; name="filename"
Content-Type: image/jpeg; charset=US-ASCII
Content-Transfer-Encoding: 8bit
${filename}
--axOhwnTOrVj2VWGGuxcaqfjgHwGQKsTFl
Content-Disposition: form-data; name="filename"; filename="Passport size photo.jpeg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
<actual file content, not shown here>
--axOhwnTOrVj2VWGGuxcaqfjgHwGQKsTFl--
I'm totally stuck on this from last 3 weeks, I did what was told in tutorials and still its not working, someone please help me out.
We don't know how to fix the issue because we don't know how the request should look like, moreover you don't show us "Parameters" tab of the HTTP Request sampler and HTTP Header Manager configuration.
So if you have another way of successfully calling this API like curl or Postman or other tool - you should be able to record the request using JMeter's HTTP(S) Test Script Recorder, see How to Convert Your Postman API Tests to JMeter for Scaling article for example setup.
If not, you need to check your API endpoint documentation, application logs or ask around for the proper request format, once you know it you should be able to amend the request yourself or provide us more details so we could assist.

Add file programmatically to IBM Connections Community

I am trying to upload files programmatically to an IBM Connections Community File library.
I am able to upload to files and then share with the community, but unfortunately is not the desired behavior.
I followed the API documentation (http://www-10.lotus.com/ldd/lcwiki.nsf/xpAPIViewer.xsp?lookupName=IBM+Connections+5.0+API+Documentation#action=openDocument&res_title=Creating_community_files_ic50&content=apicontent)
I am sending a POST to this URL: /files/basic/api/community/{community_uuid}/introspection
I tried using a file Atom Entry document, and Content-Type:application/atom+xml
But it's not working and giving me a 405 with following error:
UnsupportedOperation
-> Request sent
POST /files/basic/api/community/00f04081-f000-4752-bd88-8b73d281fb19/introspection
Content-Type: application/atom+xml
<?xml version='1.0' encoding='UTF-8'?>
<entry
xmlns:thr='http://purl.org/syndication/thread/1.0'
xmlns:opensearch='http://a9.com/-/spec/opensearch/1.1/'
xmlns:snx='http://www.ibm.com/xmlns/prod/sn'
xmlns:td='urn:ibm.com/td'
xmlns='http://www.w3.org/2005/Atom'>
<td:label>test-restore20</td:label>
<title type="text">test-restore2</title></entry>
I tried using the same method than for stand alone file, with a basic header but still giving me a 405 with following error:
UnsupportedOperation
-> Request sent:
POST /files/basic/api/community/00f04081-f000-4752-bd88-8b73d281fb19/introspection
Content-Type: binary/octet-stream
X-Update-Nonce:<Nonce>
Slug:TMap_Next_Book.pdf
Filename: /Users/Downloads/TMap_Next_Book.pdf
When I upload to myfile, works fine
-> request sent:
POST https://greenhouse.lotus.com/files/basic/api/myuserlibrary/feed
X-Update-Nonce: <Nonce>
Slug: test-restore2
Content-Type: application/binary
Filename: /Users/Downloads/client-error-log.zip
I tried the Playground, but not well documented for that part, so so far no success.
Any of you were able to do that, and would be able to share the solution?
Thanks.
Rightfully this document should be called working with IBM Connections Community Files
http://www-10.lotus.com/ldd/lcwiki.nsf/xpAPIViewer.xsp?lookupName=IBM+Connections+5.0+API+Documentation#action=openDocument&res_title=Creating_community_files_ic50&content=apicontent
The introspection endpoint should be called to get the "community collection document feed"
it doesn't look like you have the URL parameter which is required. You should use the URL with a GET /files/basic/api/community/3a246a15-b4d6-44e1-a01d-1c3d89f1f9a4/introspection?communityUuid=3a246a15-b4d6-44e1-a01d-1c3d89f1f9a4
Then you'll look for
Community Collection
Documents Feed
/
You'll then POST your file to the href --- https://greenhouse.lotus.com/files/basic/api/collection/e78ba00e-cee6-460f-a9ee-0350bf344e0b/feed
I've asked the team to change the title of the page.

SOAP statement for WCF Service

I asked about consuming a WCF service from RPG here and received this response: Scott Klement has a presentation and examples: http://www.scottklement.com/presentations/#HTTPAPI
I used SoapUI to test my service and also to get he soap statement to be used with HTTAPI. The service returnes data in SoapUI but I have been unsuccessful using it in the RPG program. SoapUI returns the following, but it seems only to work within SoapUI - it also doesn't include the path to my service which is
http://ServerName/COE/CustByNameList.svc
If I navigate to http://ServerName/COE/CustByNameList.svc?wdsl, I get the wsdl.
Statement returned in SoapUI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:GetCustomerData>
<!--Optional:-->
<tem:CustomerNumber>1688</tem:CustomerNumber>
</tem:GetCustomerData>
</soapenv:Body>
</soapenv:Envelope>
The result looks like this:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetCustomerDataResponse xmlns="http://tempuri.org/"><GetCustomerDataResult xmlns:a="http://schemas.datacontract.org/2004/07/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><a:List xmlns:b="http://schemas.datacontract.org/2004/07/WebOrderEntry.Lists"><b:PartialCSTMS><b:ADR19A>3910 LAKEFIELD DR </b:ADR19A><b:ADR29A>JOHNS CREEK FACILITY </b:ADR29A><b:CITY9A>SUWANEE </b:CITY9A><b:CST_x0023_9A>1688</b:CST_x0023_9A><b:NAME9A>JOHNSON CONTROLS </b:NAME9A><b:PHON9A>770-495-9950 </b:PHON9A><b:STAT9A>GA</b:STAT9A><b:ZIPC9A>30024 </b:ZIPC9A></b:PartialCSTMS></a:List></GetCustomerDataResult></GetCustomerDataResponse></s:Body></s:Envelope>
I keep getting 500 internal server errors. I've tried numerous variations of the SOAP statement based on the examples I have seen, but they date back to 2008. Has anyone been successful with calling a WCF service from RPG?
I asked my Twitter network and #alexeivbaranov responded with the following:
Try to compare request & response from SoapUI and your RPG client using TcpMon. As I understand your SoapUI req works fine but RPG req gets 500, so problem in request. Compare them.
Check your headers. You may be missing the soap action. Here is an example of a request to a WCF service exposed using WsHttp binding with security enabled. wsa:Action is the thing you might need.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<soapenv:Envelope
xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
xmlns:ns="http://somenamespace">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Action>http://someuri/Get</wsa:Action>
<wsa:To>http://localhost/someapp/SomeService.svc</wsa:To>
</soapenv:Header>
<soapenv:Body>
<ns:GetRequest>
<ns:Body>
<ns:Id>12345</ns:Id>
</ns:Body>
</ns:GetRequest>
</soapenv:Body>
</soapenv:Envelope>
I had to throw the towel in on using HTTPAPI to consume my WCF web service - just could not get past HTTP 400 and 500 errors. Logging wasn't helping. I believe I finally managed to get the SOAP call correct but then started receiving errors that seemed to translate into special character issues.
Instead, I ended up using IBM's IWS and got it working. These two links were of great help:
http://www.ibm.com/developerworks/ibmi/library/i-amrawsdl2rpg/index.html
http://www.iprodeveloper.com/article/rpg-programming/consume-web-services-with-ibms-iws-66209

WCF POST method doesn't get called

I've created a WCF REST service and initially used .Net Framework version 4. The service has two methods, one returns a plain string with the service status. The second allows a file to be uploaded. Both methods were working fine.
I was asked to see if the project could be moved back to only depend on .Net Framework 3.5 instead of version 4. I changed some references, and it built ok, and when I use the existing C++ client I can use the GetStatus method fine. However, now when a file gets uploaded, the client sees successful return codes to all methods, but, when I set a breakpoint at the start of WCF service's FileUpload method, it never gets executed. The file doesn't gets uploaded, it just disappears into the ether.
[ServiceContract]
internal interface IMyWebService
{
[OperationContract]
[WebGet(UriTemplate = "/Status", BodyStyle=WebMessageBodyStyle.Bare)]
Stream GetStatus();
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/FileUpload/{fileName}")]
Stream FileUpload(string fileName, Stream fileStream);
}
I've tried to use the WFetch tool as an alternative client. When I call the FileUpload method, I get this log:
started....WWWConnect::Close("localhost","80")\nclosed source port: 15800\r\n
WWWConnect::Connect("localhost","80")\nIP = "[::1]:80"\nsource port: 15866\r\n
REQUEST: **************\nPOST http://myMachine/MyService/FileUpload/hello.txt HTTP/1.1\r\n
Host: localhost\r\n
Accept: */*\r\n
Content-Length:11\r\n
\r\n
hello thereRESPONSE: **************\nHTTP/1.1 415 Missing Content Type\r\n
Content-Length: 0\r\n
Server: Microsoft-HTTPAPI/2.0\r\n
Date: Thu, 22 Sep 2011 13:26:09 GMT\r\n
\r\n
finished.
Could anybody give me any pointers for how I can diagnose this issue? I'm having trouble seeing where to start because no breakpoints get hit, and there are no error codes to investigate.
The WCF service must be doing something, because if I stop it, the client then fails to upload files, I just can't understand why execution never gets to the method that implements the POST operation.
Hmm, when using WFetch, even if I misspell the name of the method, it still seems to succeed with no error.
Thanks.
I'd start troubleshooting with the original 4.0 version of the service and a C# WCF-based test client to verify the service code will actually upload a file successfully. You could use the code in this Technet article for developing the test client.
Next, use your C++ client against the 4.0 service to verify your client will successfully send a file. Lastly, set the service back to 3.5 and see if it still works. To log messages the service is receiving for troubleshooting, look at this MSDN post to configure the built-WCF message logging capability.

WCF GZip Compression Request/Response Processing

How do I get a WCF client to process server responses which have been GZipped or Deflated by IIS?
On IIS, I've followed the instructions here on how to make IIS 6 gzip all responses (where the request contained "Accept-Encoding: gzip, deflate") emitted by .svc wcf services.
On the client, I've followed the instructions here and here on how to inject this header into the web request: "Accept-Encoding: gzip, deflate".
Fiddler2 shows the response is binary and not plain old Xml.
The client crashes with an exception which basically says there's no Xml header, which ofcourse is true.
In my IClientMessageInspector, the app crashes before AfterReceiveReply is called.
Some further notes:
(1) I can't change the WCF service or client as they are supplied by a 3rd party. I can however attach behaviors and/or message inspectors via configuration if this is the right direction to take.
(2) I don't want to compress/uncompress just the soap body, but the entire message.
Any ideas/solutions?
* SOLVED *
It was not possible to write a WCF extension to achieve these goals. Instead I followed this CodeProject article which advocate a helper class:
public class CompressibleHttpRequestCreator : IWebRequestCreate
{
public CompressibleHttpRequestCreator()
{
}
WebRequest IWebRequestCreate.Create(Uri uri)
{
HttpWebRequest httpWebRequest =
Activator.CreateInstance(typeof(HttpWebRequest),
BindingFlags.CreateInstance | BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Instance,
null, new object[] { uri, null }, null) as HttpWebRequest;
if (httpWebRequest == null)
{
return null;
}
httpWebRequest.AutomaticDecompression =DecompressionMethods.GZip |
DecompressionMethods.Deflate;
return httpWebRequest;
}
}
and also, an addition to the application configuration file:
<configuration>
<system.net>
<webRequestModules>
<remove prefix="http:"/>
<add prefix="http:"
type="Pajocomo.Net.CompressibleHttpRequestCreator, Pajocomo" />
</webRequestModules>
</system.net>
</configuration>
What seems to be happening is that WCF eventually asks some factory or other deep down in system.net to provide an HttpWebRequest instance, and we provide the helper that will be asked to create the required instance.
In the WCF client configuration file, a simple basicHttpBinding is all that is required, without the need for any custom extensions.
When the application runs, the client Http request contains the header "Accept-Encoding: gzip, deflate", the server returns a gzipped web response, and the client transparently decompresses the http response before handing it over to WCF.
When I tried to apply this technique to Web Services I found that it did NOT work. Although the helper class was executed in the same was as when used by the WCF client, the http request did not contain the "Accept-Encoding: ..." header.
To make this work for Web Services, I had to edit the Web Proxy class, and add this method:
protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
System.Net.HttpWebRequest rq = (System.Net.HttpWebRequest)base.GetWebRequest(uri);
rq.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
return rq;
}
Note that it did not matter whether the CompressibleHttpRequestCreator and block from the application config file were present or not. For web services, only overriding GetWebRequest in the Web Service Proxy worked.
Thanks for your WCF tip! We're going to be enabling IIS compression for services at my shop, and I'm hoping your solution will work.
By "To make this work for Web Services" - did you mean old school SoapHttpProtocol clients?
Because the SoapHttpProtocol class has a built-in EnableDecompression property, which will automatically handle the Compression header and response handling.
Here's an answer I gave to another question on the subject. That questio was asked from the perspective of ADO.NET Data Services, but my answer was purely about WCF.