I have installed web app server and now the server is 192.168.1.103 on IIS and i have a sample code from this site https://code.msdn.microsoft.com/office/Building-an-Office-Web-f98650d6/view/Discussions#content
in this sample the appwopiserver in web config is:
"wopihost.wingtip.com:8888/api/wopi/files/"
How can i create api/wopi/files/ directory in my server ? in other words i want to change this code to connect to my server .
here is the code that get the link:
public Link GetLink([FromUri] FileRequest fileRequest)
{
if (ModelState.IsValid)
{
var xml = WebConfigurationManager.AppSettings["appDiscoveryXml"];
var wopiServer = WebConfigurationManager.AppSettings["appWopiServer"];
bool updateEnabled = false;
bool.TryParse(WebConfigurationManager.AppSettings["updateEnabled"], out updateEnabled);
WopiAppHelper wopiHelper = new WopiAppHelper(HostingEnvironment.MapPath(xml), updateEnabled);
var result = wopiHelper.GetDocumentLink(wopiServer + fileRequest.name);
var rv = new Link
{
Url = result
};
return rv;
}
throw new ApplicationException("Invalid ModelState");
}
the final created link to open office in browser in this sample is:
http://owa1.wingtip.com/we/wordeditorframe.aspx?WOPISrc=http%3a%2f%2fwopihost.wingtip.com%3a8888%2fapi%2fwopi%2ffiles%2ftest.docx&access_token=YMDZjBxXlD4%3dlxnjDAq1aib0yGsNDo%2fd0Jm4b5R8eJircFrcaU84fgQ%3d
but i want something like this:
(http:// 192.168.1.103/we/wordeditorframe.aspx?WOPISrc=http%3a%2f%2fwopihost.wingtip.com%3a8888%2fapi%2fwopi%2ffiles%2ftest.docx&access_token=YMDZjBxXlD4%3dlxnjDAq1aib0yGsNDo%2fd0Jm4b5R8eJircFrcaU84fgQ%3d)
You have to replace App_Data\Discovery.xml with an XML you find at http://192.168.1.103/hosting/discovery (your OWA server).
Related
UPDATE: I've uploaded a repo - https://github.com/mrpmorris/CannotIntegrationTestWebApp/blob/master/TestProject1/UnitTest1.cs
I have a web server that serves both HTTPS and WebSocket requests. When I run the app I am able to connect and make requests from postman for both HTTPS://localhost:8080 and WSS://localhost:8080/game-server
using Gambit.ApplicationLayer;
using Gambit.GameServer.Configuration;
using Gambit.GameServer.UseCases;
namespace Gambit.GameServer;
public class Program
{
public static async Task Main(string[] args)
{
WebApplication app = BuildApp(args);
await RunAppAsync(app);
}
public static WebApplication BuildApp(string[] args, Action<WebApplicationBuilder>? configure = null)
{
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
IServiceCollection services = builder.Services;
IConfiguration configuration = builder.Configuration;
IWebHostEnvironment environment = builder.Environment;
services.AddControllers();
services.AddLogging(opts =>
{
opts.ClearProviders();
opts.AddConfiguration(configuration.GetSection("Logging"));
opts.AddDebug();
opts.AddEventSourceLogger();
#if DEBUG
if (environment.IsDevelopment())
opts.AddConsole();
#endif
});
services.Configure<GameServerOptions>(configuration.GetSection("GameServer"));
services.AddApplicationServices(configuration);
configure?.Invoke(builder);
WebApplication app = builder.Build();
return app;
}
public static async Task RunAppAsync(WebApplication app)
{
app.MapGet("/", () => "Gambit.Server.API is running");
app.AddUserUseCases();
app.AddGameUseCases();
app.MapControllers();
app.UseWebSockets();
await app.RunAsync();
}
}
When I run my unit tests I use the same code to create and run the server (once per test run) my tests are able to make HTTPS requests but not connect via a WebSocket. When I try, I get a 404 error. I experience the same in PostMan.
static IntegrationTestsServer()
{
ConfigureMocks();
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "IntegrationTesting");
var app = Program.BuildApp(Array.Empty<string>(), builder =>
{
builder.WebHost.UseSetting("urls", "https://localhost:8080");
});
Configuration = app.Services.GetRequiredService<IConfiguration>();
GameServerOptions = app.Services.GetRequiredService<IOptions<GameServerOptions>>();
var dbContextOptions = app.Services.GetRequiredService<DbContextOptions<ApplicationDbContext>>();
using var dbContext = new ApplicationDbContext(dbContextOptions);
dbContext.Database.EnsureDeleted();
dbContext.Database.EnsureCreated();
HttpClient = new HttpClient { BaseAddress = new Uri("https://localhost:8080") };
_ = Program.RunAppAsync(app);
}
I can even perform a successful HttpClient.GetAsync("https://localhost:8080") immediately before the ClientWebSocket fails
System.Net.WebSockets.WebSocketException : The server returned status code '404' when status code '101' was expected.
Does anyone have any ideas why this might be?
Set ApplicationName in the WebApplicationOptions sent to WebApplication.CreateBuilder
WebApplication.CreateBuilder
(
new WebApplicationOptions
{
ApplicationName = typeof(Gambit.GameServer.Program).Assembly.GetName().Name // <==
}
);
Now it will be able to find your manifest file when running from a test.
See the following blog post for more of the back story on how I figured it out.
https://thefreezeteam.com/posts/StevenTCramer/2022/08/25/runwebserverintest
I need to call my .NET (C#) web service from a classic asp page. I want to test it by creating a console application that calls the asp page.
This is my asp page:
Dim strUserID
Dim strUserName
Dim strUserEmail
strUserID = Request.Form("UserID")
strUserName = Request.Form("UserName")
strUserEmail = Request.Form("UserEMail")
SET objSoapClient = Server.CreateObject("MSSOAP.SoapClient")
objSoapClient.ClientProperty("ServerHTTPRequest") = True
Call objSoapClient.mssoapinit("http://localhost:/MyWebService/Service1/" & _
"MyWebService.asmx?WSDL", "MyWebService")
strReturnValue = objSoapClient.SendData(strUserID, strUserName, strUserEmail)
response.Write("Returned from service with return value: " & strReturnValue)
Now my console application has to call the .asp page.
How do I construct the URL?
If the asp page is located in this folder: C:\Folder1\OldPage.asp, how do I construct the URL?
This is what I have so far:
static void Main(string[] args)
{
WebClient client = new WebClient();
Uri aspPagingServiceUri = new Uri("http://localhost/Folder1/OldPage.asp?UserID=g39s24&UserName=Gloria Test$UserEmail=gtest#hvhs.org");
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(aspPagingServiceUri);
httpWebRequest.Method = "GET";
var response = httpWebRequest.GetResponse();
HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse();
Stream resStream = resp.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
string strResponse = reader.ReadToEnd();
Console.WriteLine(strResponse);
reader.Close();
}
I get the error: 'The remote server returned an error: (503) Server Unavailable. ' when it gets to the GetResponse function.
I believe my problem is with the creation of the URL.
Thanks.
UPDATE
I have trying to connect to the ASP file that on the web server. I am getting a (500) error: "The remote server returned an error: (500) Internal Server Error."
The file is folder: C:\inetpub/wwwroot/Apps/Services/ServiceNew.asp
This is my console application:
static void Main(string[] args)
{
try
{
WebClient client = new WebClient();
Uri aspPagingServiceUri = new Uri("http://myserverName/Apps/Services/ServiceNew.asp?UserID=g39r345&UserName=John Smith&UserEmail=jsmith#mydomain.com&Subject=Test&MSG=Testing&ContactList=Sam Smith;");
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(aspPagingServiceUri);
httpWebRequest.Method = "GET";
var response = httpWebRequest.GetResponse();
HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse();
Stream resStream = resp.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
string strResponse = reader.ReadToEnd();
Console.WriteLine(strResponse);
reader.Close();
}
catch (WebException wex)
{
Console.WriteLine("Web Exception: " + wex.Message);
}
catch (Exception ex)
{
Console.WriteLine("General Exception: " + ex.Message);
}
}
The error is occurring var response = httpWebRequest.GetResponse();
Am I creating the URL correctly?
I am just following the file path.
You can not execute ASP code directly. What you need is to setup a web server that can execute classic ASP, i.e. Internet Information Services (IIS) on your machine, on another computer in a local network or externally.
IIS is part of some Windows distributions, you may just have to activate it. Make sure to install the classic ASP module, as this is not installed by default nowadays.
A warning: classic ASP often depends on additional COM components. So you may have to install more to get your code working.
I am creating an application in xamarin forms which needs synchronous web service call. But only GetAsync is available in xamarin forms. can anyone please explain me how to call synchronous web service call in xamarin forms?
Try something like this
public Webservice() { }
public Home GetHome()
{
string strpost = "";
var client = new System.Net.Http.HttpClient();
client.BaseAddress = new Uri(" xyz ");
var response = client.PostAsync(new Uri(" xyz "), str).Result;
var result = JsonConvert.DeserializeObject<Home>(response.Content.ReadAsStringAsync().Result);
Home home = new Home();
if (!Equals(result, null))
{
home = result;
return home;
}
}
Refer: https://forums.xamarin.com/discussion/43397/how-to-call-synchronous-webservice
I have a processing page and I want to run function process all via web service (add web reference into my C# window form app). My code below:
var context = new ModuleABCService.Screen() // limk web services: http://localhost:8686/soap/DMSBL009.asmx
{
CookieContainer = new CookieContainer(),
AllowAutoRedirect = true,
EnableDecompression = true,
Timeout = 60000
};
var loginResult = context.Login(string.Format("{0}#{1}", val.UserName, company), val.Password);
if (loginResult.Code != ErrorCode.OK)
{
throw new Exception(string.Format("Can not login {0}", company));
}
Content content = context.GetSchema();
context.Clear();
context.Submit(
new Command[]
{
content.Actions.ProcessAll
}
);
And I got an exception message:
System.Web.Services.Protocols.SoapExceptio:n Server was unable to process request. ---> PX.Data.PXUndefinedCompanyException: Unable determine proper company id for the request. at PX.Data.PXDatabaseProviderBase.getCompanyID(String tableName, companySetting& setting) in c:\Builders\4_10-2014_4_28-21_21_17-Full\Scripts\BuildTemp\NetTools\PX.Data\Database\Common\DbProviderBaseCompanies.cs:line 471...
Have you ever got this error before? Could you please give me any suggestion? Thank you so much!
Ok, I found out, because Acumatica's license
i tried to connect REST web servie from windows phone 8 application.
it was working proberly for weeks but after no change in it I get this generic error :
System.Net.WebException: The remote server returned an error:
NotFound.
i tried to test it by online REST Clients and services works properly
i tried to handle Exception and parse it as webException by this code :
var we = ex.InnerException as WebException;
if (we != null)
{
var resp = we.Response as HttpWebResponse;
response.StatusCode = resp.StatusCode;
and i get no more information and final response code is : "NotFound"
any one have any idea about what may cause this error?
there is already a trusted Certificate implemented on the server . the one who has the server suggested to have a DNS entry for the server, this entry should be at the customer DNS or in the phone hosts file .that what i done and worked for awhile but now it doesn't work however i checked that there is no thing changed
this is sample for Get Request it works proberly on Windwos Store apps :
async Task<object> GetHttps(string uri, string parRequest, Type returnType, params string[] parameters)
{
try
{
string strRequest = ConstructRequest(parRequest, parameters);
string encodedRequest = HttpUtility.UrlEncode(strRequest);
string requestURL = BackEndURL + uri + encodedRequest;
HttpWebRequest request = HttpWebRequest.Create(new Uri(requestURL, UriKind.Absolute)) as HttpWebRequest;
request.Headers["applicationName"] = AppName;
request.Headers["applicationPassword"] = AppPassword;
if (AppVersion > 1)
request.Headers["applicationVersion"] = AppVersion.ToString();
request.Method = "GET";
request.CookieContainer = cookieContainer;
var factory = new TaskFactory();
var getResponseTask = factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null);
HttpWebResponse response = await getResponseTask as HttpWebResponse;
// string s = response.GetResponseStream().ToString();
if (response.StatusCode == HttpStatusCode.OK)
{
XmlSerializer serializer = new XmlSerializer(returnType);
object obj = serializer.Deserialize(response.GetResponseStream());
return obj;
}
else
{
var Instance = Activator.CreateInstance(returnType);
(Instance as ResponseBase).NetworkError = true;
(Instance as ResponseBase).StatusCode = response.StatusCode;
return Instance;
}
}
catch (Exception ex)
{
return HandleException(ex, returnType);
}
}
i tried to monitor connections from Emulator and i found this error in connection :
**
Authentication failed because the remote party has closed the
transport stream.
**
You saw the client implement a server side certificate in the service. Did you have that certificate installed on the phone? That can be the cause of the NotFound error. Please, can you try to navigate to the service in the phone or emulator internet explorer prior to testing the app? If you do that, you can see the service working in the emulator/phone internet explorer? Maybe at that point internet explorer ask you about installing the certificate and then you can open your app, and it works.
Also remember if you are testing this in the emulator, every time you close it, the state is lost so you need to repeat the operation of installing the certificate again.
Hope this helps.
If you plan to use SSL in production in general public application (not company-distribution app), you need to ensure your certificate has one of the following root authorities:
SSL root certificates for Windows Phone OS 7.1.
When we had same issue, we purchased SSL certificate from one of those providers and after installing it on server we were able to make HTTPS requests to our services with no problem.
If you have company-distribution app, you can use any certificate from company's Root CA.